Python | Numpy.expand_dims() method (original) (raw)
Last Updated : 17 Sep, 2019
With the help of **Numpy.expand_dims()**
method, we can get the expanded dimensions of an array by using Numpy.expand_dims()
method.
Syntax :
Numpy.expand_dims()
Return : Return the expanded array.
Example #1 :
In this example we can see that using Numpy.expand_dims()
method, we are able to get the expanded array using this method.
import
numpy as np
gfg
=
np.array([
1
,
2
])
print
(gfg.shape)
gfg
=
np.expand_dims(gfg, axis
=
0
)
print
(gfg.shape)
Output :
(2, )
(1, 2)
Example #2 :
import
numpy as np
gfg
=
np.array([[
1
,
2
], [
7
,
8
]])
print
(gfg.shape)
gfg
=
np.expand_dims(gfg, axis
=
0
)
print
(gfg.shape)
Output :
(2, 2)
(1, 2, 2)
Similar Reads
- Python | Numpy expandtabs() method With the help of numpy.char.expandtabs() method, we can expand the tab using numpy method in the single statement. Syntax : numpy.char.expandtabs() Return : Return the string array having expanded tabs. Example #1 : In this example we can see that by using numpy.char.expandtabs() method, we are able 1 min read
- Python | Numpy.dsplit() method With the help of Numpy.dsplit()() method, we can get the splitted dimensions of an array by using Numpy.dsplit()() method. Syntax : Numpy.dsplit(numpy.array(), split_size) Return : Return the array having splitted dimensions. Example #1 : In this example we can see that using Numpy.expand_dims() met 1 min read
- Python | numpy.fill_diagonal() method With the help of numpy.fill_diagonal() method, we can get filled the diagonals of numpy array with the value passed as the parameter in numpy.fill_diagonal() method. Syntax : numpy.fill_diagonal(array, value) Return : Return the filled value in the diagonal of an array. Example #1 : In this example 1 min read
- Python | sympy.expand_pow_exp() method With the help of sympy.expand_pow_exp() method, we can expand mathematical expression using following identity - x(a+b) = xa.xb Syntax: expand_pow_exp(expression) Parameters: expression - It is the mathematical expression which needs to be expanded.Returns: Returns an expanded mathematical expressio 1 min read
- numpy.nanprod() in Python numpy.nanprod() function is used when we want to compute the product of array elements over a given axis treating NaNs as ones. One is returned for slices that are all-NaN or empty. Syntax : numpy.nanprod(arr, axis=None, dtype=None, out=None, keepdims='class numpy._globals._NoValue'). Parameters : a 2 min read
- Python | numpy.array_split() method With the help of numpy.array_split() method, we can get the splitted array of having different dimensions by using numpy.array_split() method. Syntax : numpy.array_split() Return : Return the splitted array of one dimension. Example #1 : In this example we can see that by using numpy.array_split() m 1 min read
- numpy.nansum() in Python numpy.nansum()function is used when we want to compute the sum of array elements over a given axis treating Not a Numbers (NaNs) as zero. Syntax : numpy.nansum(arr, axis=None, dtype=None, out=None, keepdims='no value') Parameters : arr : [array_like] Array containing numbers whose sum is desired. If 3 min read
- numpy.matrix() in Python This class returns a matrix from a string of data or array-like object. Matrix obtained is a specialised 2D array. Syntax : numpy.matrix(data, dtype = None) : Parameters : data : data needs to be array-like or string dtype : Data type of returned array. Returns : data interpreted as a matrix # Pytho 1 min read
- numpy.nonzero() in Python numpy.nonzero()function is used to Compute the indices of the elements that are non-zero. It returns a tuple of arrays, one for each dimension of arr, containing the indices of the non-zero elements in that dimension. The corresponding non-zero values in the array can be obtained with arr[nonzero(ar 2 min read
- Python | Numpy np.as_series() method With the help of np.as_series() method, we can get a 1-D series from multidimensional array by using np.as_series() method. Syntax : np.as_series(array) Return : Return a 1-D series. Example #1 : In this example we can see that by using np.as_series() method, we are able to get the 1-D series from m 1 min read