MCPcopy
hub / github.com/numpy/numpy / atleast_2d

Function atleast_2d

numpy/_core/shape_base.py:79–130  ·  view source on GitHub ↗

View inputs as arrays with at least two dimensions. Parameters ---------- arys1, arys2, ... : array_like One or more array-like sequences. Non-array inputs are converted to arrays. Arrays that already have two or more dimensions are preserved. Returns

(*arys)

Source from the content-addressed store, hash-verified

77
78@array_function_dispatch(_atleast_2d_dispatcher)
79def atleast_2d(*arys):
80 """
81 View inputs as arrays with at least two dimensions.
82
83 Parameters
84 ----------
85 arys1, arys2, ... : array_like
86 One or more array-like sequences. Non-array inputs are converted
87 to arrays. Arrays that already have two or more dimensions are
88 preserved.
89
90 Returns
91 -------
92 res, res2, ... : ndarray
93 An array, or tuple of arrays, each with ``a.ndim >= 2``.
94 Copies are avoided where possible, and views with two or more
95 dimensions are returned.
96
97 See Also
98 --------
99 atleast_1d, atleast_3d
100
101 Examples
102 --------
103 >>> import numpy as np
104 >>> np.atleast_2d(3.0)
105 array([[3.]])
106
107 >>> x = np.arange(3.0)
108 >>> np.atleast_2d(x)
109 array([[0., 1., 2.]])
110 >>> np.atleast_2d(x).base is x
111 True
112
113 >>> np.atleast_2d(1, [1, 2], [[1, 2]])
114 (array([[1]]), array([[1, 2]]), array([[1, 2]]))
115
116 """
117 res = []
118 for ary in arys:
119 ary = asanyarray(ary)
120 if ary.ndim == 0:
121 result = ary.reshape(1, 1)
122 elif ary.ndim == 1:
123 result = ary[_nx.newaxis, :]
124 else:
125 result = ary
126 res.append(result)
127 if len(res) == 1:
128 return res[0]
129 else:
130 return tuple(res)
131
132
133def _atleast_3d_dispatcher(*arys):

Callers 10

test_0D_arrayMethod · 0.90
test_1D_arrayMethod · 0.90
test_2D_arrayMethod · 0.90
test_3D_arrayMethod · 0.90
test_r2arrayMethod · 0.90
multi_dotFunction · 0.90
test_emptyMethod · 0.90
vstackFunction · 0.85
test_atleast_2dMethod · 0.85
test_shape_scalarMethod · 0.85

Calls 2

asanyarrayFunction · 0.85
reshapeMethod · 0.80

Tested by 8

test_0D_arrayMethod · 0.72
test_1D_arrayMethod · 0.72
test_2D_arrayMethod · 0.72
test_3D_arrayMethod · 0.72
test_r2arrayMethod · 0.72
test_emptyMethod · 0.72
test_atleast_2dMethod · 0.68
test_shape_scalarMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…