nlcpy.expand_dims¶
-
nlcpy.
expand_dims
(a, axis)[source]¶ Expands the shape of an array.
Insert a new axis that will appear at the axis position in the expanded array shape.
- Parameters
- aarray_like
Input array.
- axisint
Position in the expanded axes where the new axis is placed.
- Returns
- resndarray
View of a with the number of dimensions increased by one.
See also
Examples
>>> import nlcpy as vp >>> x = vp.array([1,2]) >>> x.shape (2,)
The following is equivalent to x[vp.newaxis,:] or x[vp.newaxis]:
>>> y = vp.expand_dims(x, axis=0) >>> y array([[1, 2]]) >>> y.shape (1, 2) >>> y = vp.expand_dims(x, axis=1) # Equivalent to x[:,vp.newaxis] >>> y array([[1], [2]]) >>> y.shape (2, 1)
Note that some examples may use None instead of vp.newaxis. These are the same objects:
>>> vp.newaxis is None True