MCPcopy Index your code
hub / github.com/numpy/numpy / _ensure_ndmin_ndarray

Function _ensure_ndmin_ndarray

numpy/lib/_npyio_impl.py:803–823  ·  view source on GitHub ↗

This is a helper function of loadtxt and genfromtxt to ensure proper minimum dimension as requested ndim : int. Supported values 1, 2, 3 ^^ whenever this changes, keep in sync with _ensure_ndmin_ndarray_check_param

(a, *, ndmin: int)

Source from the content-addressed store, hash-verified

801 raise ValueError(f"Illegal value of ndmin keyword: {ndmin}")
802
803def _ensure_ndmin_ndarray(a, *, ndmin: int):
804 """This is a helper function of loadtxt and genfromtxt to ensure
805 proper minimum dimension as requested
806
807 ndim : int. Supported values 1, 2, 3
808 ^^ whenever this changes, keep in sync with
809 _ensure_ndmin_ndarray_check_param
810 """
811 # Verify that the array has at least dimensions `ndmin`.
812 # Tweak the size and shape of the arrays - remove extraneous dimensions
813 if a.ndim > ndmin:
814 a = np.squeeze(a)
815 # and ensure we have the minimum number of dimensions asked for
816 # - has to be in this order for the odd case ndmin=1, a.squeeze().ndim=0
817 if a.ndim < ndmin:
818 if ndmin == 1:
819 a = np.atleast_1d(a)
820 elif ndmin == 2:
821 a = np.atleast_2d(a).T
822
823 return a
824
825
826# amount of lines loadtxt reads in one chunk, can be overridden for testing

Callers 2

_readFunction · 0.85
genfromtxtFunction · 0.85

Calls 1

squeezeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…