1
__all__ = ['atleast_1d','atleast_2d','atleast_3d','vstack','hstack']
4
from numeric import array, asarray, newaxis
8
Convert inputs to arrays with at least one dimension.
10
Scalar inputs are converted to 1-dimensional arrays, whilst
11
higher-dimensional inputs are preserved.
15
array1, array2, ... : array_like
16
One or more input arrays.
21
An array, or sequence of arrays, each with ``a.ndim >= 1``.
22
Copies are made only if necessary.
26
atleast_2d, atleast_3d
30
>>> np.atleast_1d(1.0)
33
>>> x = np.arange(9.0).reshape(3,3)
38
>>> np.atleast_1d(x) is x
41
>>> np.atleast_1d(1, [3, 4])
42
[array([1]), array([3, 4])]
47
res.append(array(ary,copy=False,subok=True,ndmin=1))
53
def atleast_2d(*arys):
55
View inputs as arrays with at least two dimensions.
59
array1, array2, ... : array_like
60
One or more array-like sequences. Non-array inputs are converted
61
to arrays. Arrays that already have two or more dimensions are
66
res, res2, ... : ndarray
67
An array, or tuple of arrays, each with ``a.ndim >= 2``.
68
Copies are avoided where possible, and views with two or more
69
dimensions are returned.
73
atleast_1d, atleast_3d
77
>>> np.atleast_2d(3.0)
80
>>> x = np.arange(3.0)
82
array([[ 0., 1., 2.]])
83
>>> np.atleast_2d(x).base is x
86
>>> np.atleast_2d(1, [1, 2], [[1, 2]])
87
[array([[1]]), array([[1, 2]]), array([[1, 2]])]
92
res.append(array(ary,copy=False,subok=True,ndmin=2))
98
def atleast_3d(*arys):
100
View inputs as arrays with at least three dimensions.
104
array1, array2, ... : array_like
105
One or more array-like sequences. Non-array inputs are converted
106
to arrays. Arrays that already have three or more dimensions are
111
res1, res2, ... : ndarray
112
An array, or tuple of arrays, each with ``a.ndim >= 3``.
113
Copies are avoided where possible, and views with three or more
114
dimensions are returned. For example, a 1-D array of shape ``N``
115
becomes a view of shape ``(1, N, 1)``. A 2-D array of shape ``(M, N)``
116
becomes a view of shape ``(M, N, 1)``.
120
atleast_1d, atleast_2d
124
>>> np.atleast_3d(3.0)
127
>>> x = np.arange(3.0)
128
>>> np.atleast_3d(x).shape
131
>>> x = np.arange(12.0).reshape(4,3)
132
>>> np.atleast_3d(x).shape
134
>>> np.atleast_3d(x).base is x
137
>>> for arr in np.atleast_3d([1, 2], [[1, 2]], [[[1, 2]]]):
138
... print arr, arr.shape
150
if len(ary.shape) == 0:
151
result = ary.reshape(1,1,1)
152
elif len(ary.shape) == 1:
153
result = ary[newaxis,:,newaxis]
154
elif len(ary.shape) == 2:
155
result = ary[:,:,newaxis]
167
Stack arrays in sequence vertically (row wise).
169
Take a sequence of arrays and stack them vertically to make a single
170
array. Rebuild arrays divided by `vsplit`.
174
tup : sequence of ndarrays
175
Tuple containing arrays to be stacked. The arrays must have the same
176
shape along all but the first axis.
181
The array formed by stacking the given arrays.
185
hstack : Stack arrays in sequence horizontally (column wise).
186
dstack : Stack arrays in sequence depth wise (along third dimension).
187
concatenate : Join a sequence of arrays together.
188
vsplit : Split array into a list of multiple sub-arrays vertically.
193
Equivalent to ``np.concatenate(tup, axis=0)``
197
>>> a = np.array([1, 2, 3])
198
>>> b = np.array([2, 3, 4])
203
>>> a = np.array([[1], [2], [3]])
204
>>> b = np.array([[2], [3], [4]])
214
return _nx.concatenate(map(atleast_2d,tup),0)
218
Stack arrays in sequence horizontally (column wise).
220
Take a sequence of arrays and stack them horizontally to make
221
a single array. Rebuild arrays divided by ``hsplit``.
225
tup : sequence of ndarrays
226
All arrays must have the same shape along all but the second axis.
231
The array formed by stacking the given arrays.
235
vstack : Stack arrays in sequence vertically (row wise).
236
dstack : Stack arrays in sequence depth wise (along third axis).
237
concatenate : Join a sequence of arrays together.
238
hsplit : Split array along second axis.
242
Equivalent to ``np.concatenate(tup, axis=1)``
246
>>> a = np.array((1,2,3))
247
>>> b = np.array((2,3,4))
249
array([1, 2, 3, 2, 3, 4])
250
>>> a = np.array([[1],[2],[3]])
251
>>> b = np.array([[2],[3],[4]])
258
return _nx.concatenate(map(atleast_1d,tup),1)