249
249
axis = axis + len(shape) + 1
250
250
return a.reshape(shape[:axis] + (1,) + shape[axis:])
253
def atleast_1d(*arys):
255
Convert inputs to arrays with at least one dimension.
257
Scalar inputs are converted to 1-dimensional arrays, whilst
258
higher-dimensional inputs are preserved.
262
array1, array2, ... : array_like
263
One or more input arrays.
268
An array, or sequence of arrays, each with ``a.ndim >= 1``.
269
Copies are made only if necessary.
273
atleast_2d, atleast_3d
277
>>> np.atleast_1d(1.0)
280
>>> x = np.arange(9.0).reshape(3,3)
282
array([[ 0., 1., 2.],
285
>>> np.atleast_1d(x) is x
288
>>> np.atleast_1d(1, [3, 4])
289
[array([1]), array([3, 4])]
294
res.append(array(ary,copy=False,subok=True,ndmin=1))
300
def atleast_2d(*arys):
302
View inputs as arrays with at least two dimensions.
306
array1, array2, ... : array_like
307
One or more array-like sequences. Non-array inputs are converted
308
to arrays. Arrays that already have two or more dimensions are
313
res, res2, ... : ndarray
314
An array, or tuple of arrays, each with ``a.ndim >= 2``.
315
Copies are avoided where possible, and views with two or more
316
dimensions are returned.
320
atleast_1d, atleast_3d
324
>>> np.atleast_2d(3.0)
327
>>> x = np.arange(3.0)
329
array([[ 0., 1., 2.]])
330
>>> np.atleast_2d(x).base is x
333
>>> np.atleast_2d(1, [1, 2], [[1, 2]])
334
[array([[1]]), array([[1, 2]]), array([[1, 2]])]
339
res.append(array(ary,copy=False,subok=True,ndmin=2))
345
def atleast_3d(*arys):
347
View inputs as arrays with at least three dimensions.
351
array1, array2, ... : array_like
352
One or more array-like sequences. Non-array inputs are converted
353
to arrays. Arrays that already have three or more dimensions are
358
res1, res2, ... : ndarray
359
An array, or tuple of arrays, each with ``a.ndim >= 3``.
360
Copies are avoided where possible, and views with three or more
361
dimensions are returned. For example, a 1-D array of shape ``N``
362
becomes a view of shape ``(1, N, 1)``. A 2-D array of shape ``(M, N)``
363
becomes a view of shape ``(M, N, 1)``.
367
atleast_1d, atleast_2d
371
>>> np.atleast_3d(3.0)
374
>>> x = np.arange(3.0)
375
>>> np.atleast_3d(x).shape
378
>>> x = np.arange(12.0).reshape(4,3)
379
>>> np.atleast_3d(x).shape
381
>>> np.atleast_3d(x).base is x
384
>>> for arr in np.atleast_3d([1, 2], [[1, 2]], [[[1, 2]]]):
385
... print arr, arr.shape
397
if len(ary.shape) == 0:
398
result = ary.reshape(1,1,1)
399
elif len(ary.shape) == 1:
400
result = ary[newaxis,:,newaxis]
401
elif len(ary.shape) == 2:
402
result = ary[:,:,newaxis]
414
Stack arrays in sequence vertically (row wise).
416
Take a sequence of arrays and stack them vertically to make a single
417
array. Rebuild arrays divided by `vsplit`.
421
tup : sequence of ndarrays
422
Tuple containing arrays to be stacked. The arrays must have the same
423
shape along all but the first axis.
428
The array formed by stacking the given arrays.
432
hstack : Stack arrays in sequence horizontally (column wise).
433
dstack : Stack arrays in sequence depth wise (along third dimension).
434
concatenate : Join a sequence of arrays together.
435
vsplit : Split array into a list of multiple sub-arrays vertically.
440
Equivalent to ``np.concatenate(tup, axis=0)``
444
>>> a = np.array([1, 2, 3])
445
>>> b = np.array([2, 3, 4])
450
>>> a = np.array([[1], [2], [3]])
451
>>> b = np.array([[2], [3], [4]])
461
return _nx.concatenate(map(atleast_2d,tup),0)
465
Stack arrays in sequence horizontally (column wise).
467
Take a sequence of arrays and stack them horizontally to make
468
a single array. Rebuild arrays divided by ``hsplit``.
472
tup : sequence of ndarrays
473
All arrays must have the same shape along all but the second axis.
478
The array formed by stacking the given arrays.
482
vstack : Stack arrays in sequence vertically (row wise).
483
dstack : Stack arrays in sequence depth wise (along third axis).
484
concatenate : Join a sequence of arrays together.
485
hsplit : Split array along second axis.
489
Equivalent to ``np.concatenate(tup, axis=1)``
493
>>> a = np.array((1,2,3))
494
>>> b = np.array((2,3,4))
496
array([1, 2, 3, 2, 3, 4])
497
>>> a = np.array([[1],[2],[3]])
498
>>> b = np.array([[2],[3],[4]])
505
return _nx.concatenate(map(atleast_1d,tup),1)
507
252
row_stack = vstack
509
254
def column_stack(tup):