MCPcopy
hub / github.com/numpy/numpy / atleast_1d

Function atleast_1d

numpy/_core/shape_base.py:20–71  ·  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

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

Used in the wild real call sites across dependent graphs

searching dependent graphs…