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

Function atleast_1d

numpy/core/shape_base.py:24–74  ·  view source on GitHub ↗

Convert inputs to arrays with at least one dimension. Scalar inputs are converted to 1-dimensional arrays, whilst higher-dimensional inputs are preserved. Parameters ---------- arys1, arys2, ... : array_like One or more input arrays. Returns ------- re

(*arys)

Source from the content-addressed store, hash-verified

22
23@array_function_dispatch(_atleast_1d_dispatcher)
24def atleast_1d(*arys):
25 """
26 Convert inputs to arrays with at least one dimension.
27
28 Scalar inputs are converted to 1-dimensional arrays, whilst
29 higher-dimensional inputs are preserved.
30
31 Parameters
32 ----------
33 arys1, arys2, ... : array_like
34 One or more input arrays.
35
36 Returns
37 -------
38 ret : ndarray
39 An array, or list of arrays, each with ``a.ndim >= 1``.
40 Copies are made only if necessary.
41
42 See Also
43 --------
44 atleast_2d, atleast_3d
45
46 Examples
47 --------
48 >>> np.atleast_1d(1.0)
49 array([1.])
50
51 >>> x = np.arange(9.0).reshape(3,3)
52 >>> np.atleast_1d(x)
53 array([[0., 1., 2.],
54 [3., 4., 5.],
55 [6., 7., 8.]])
56 >>> np.atleast_1d(x) is x
57 True
58
59 >>> np.atleast_1d(1, [3, 4])
60 [array([1]), array([3, 4])]
61
62 """
63 res = []
64 for ary in arys:
65 ary = asanyarray(ary)
66 if ary.ndim == 0:
67 result = ary.reshape(1)
68 else:
69 result = ary
70 res.append(result)
71 if len(res) == 1:
72 return res[0]
73 else:
74 return res
75
76
77def _atleast_2d_dispatcher(*arys):

Callers 14

test_0D_arrayMethod · 0.90
test_1D_arrayMethod · 0.90
test_2D_arrayMethod · 0.90
test_3D_arrayMethod · 0.90
test_r1arrayMethod · 0.90
polyFunction · 0.90
rootsFunction · 0.90
polyintFunction · 0.90
polyaddFunction · 0.90
polysubFunction · 0.90
polydivFunction · 0.90
__init__Method · 0.90

Calls 2

asanyarrayFunction · 0.85
reshapeMethod · 0.80

Tested by 6

test_0D_arrayMethod · 0.72
test_1D_arrayMethod · 0.72
test_2D_arrayMethod · 0.72
test_3D_arrayMethod · 0.72
test_r1arrayMethod · 0.72
test_shape_scalarMethod · 0.68