MCPcopy Create free account
hub / github.com/numpy/numpy / _read

Function _read

numpy/lib/npyio.py:818–1095  ·  view source on GitHub ↗

r""" Read a NumPy array from a text file. Parameters ---------- fname : str or file object The filename or the file to be read. delimiter : str, optional Field delimiter of the fields in line of the file. Default is a comma, ','. If None any sequence of

(fname, *, delimiter=',', comment='#', quote='"',
          imaginary_unit='j', usecols=None, skiplines=0,
          max_rows=None, converters=None, ndmin=None, unpack=False,
          dtype=np.float64, encoding="bytes")

Source from the content-addressed store, hash-verified

816
817
818def _read(fname, *, delimiter=',', comment='#', quote='"',
819 imaginary_unit='j', usecols=None, skiplines=0,
820 max_rows=None, converters=None, ndmin=None, unpack=False,
821 dtype=np.float64, encoding="bytes"):
822 r"""
823 Read a NumPy array from a text file.
824
825 Parameters
826 ----------
827 fname : str or file object
828 The filename or the file to be read.
829 delimiter : str, optional
830 Field delimiter of the fields in line of the file.
831 Default is a comma, ','. If None any sequence of whitespace is
832 considered a delimiter.
833 comment : str or sequence of str or None, optional
834 Character that begins a comment. All text from the comment
835 character to the end of the line is ignored.
836 Multiple comments or multiple-character comment strings are supported,
837 but may be slower and `quote` must be empty if used.
838 Use None to disable all use of comments.
839 quote : str or None, optional
840 Character that is used to quote string fields. Default is '"'
841 (a double quote). Use None to disable quote support.
842 imaginary_unit : str, optional
843 Character that represent the imaginay unit `sqrt(-1)`.
844 Default is 'j'.
845 usecols : array_like, optional
846 A one-dimensional array of integer column numbers. These are the
847 columns from the file to be included in the array. If this value
848 is not given, all the columns are used.
849 skiplines : int, optional
850 Number of lines to skip before interpreting the data in the file.
851 max_rows : int, optional
852 Maximum number of rows of data to read. Default is to read the
853 entire file.
854 converters : dict or callable, optional
855 A function to parse all columns strings into the desired value, or
856 a dictionary mapping column number to a parser function.
857 E.g. if column 0 is a date string: ``converters = {0: datestr2num}``.
858 Converters can also be used to provide a default value for missing
859 data, e.g. ``converters = lambda s: float(s.strip() or 0)`` will
860 convert empty fields to 0.
861 Default: None
862 ndmin : int, optional
863 Minimum dimension of the array returned.
864 Allowed values are 0, 1 or 2. Default is 0.
865 unpack : bool, optional
866 If True, the returned array is transposed, so that arguments may be
867 unpacked using ``x, y, z = read(...)``. When used with a structured
868 data-type, arrays are returned for each field. Default is False.
869 dtype : numpy data type
870 A NumPy dtype instance, can be a structured dtype to map to the
871 columns of the file.
872 encoding : str, optional
873 Encoding used to decode the inputfile. The special value 'bytes'
874 (the default) enables backwards-compatible behavior for `converters`,
875 ensuring that inputs to the converter functions are encoded

Callers 1

loadtxtFunction · 0.85

Calls 10

_check_nonneg_intFunction · 0.85
_preprocess_commentsFunction · 0.85
_load_from_filelikeFunction · 0.85
_ensure_ndmin_ndarrayFunction · 0.85
astypeMethod · 0.80
warnMethod · 0.80
minFunction · 0.50
dtypeMethod · 0.45
openMethod · 0.45

Tested by

no test coverage detected