Open In App

numpy.ndarray.ndim() method | Python

Last Updated : 26 Mar, 2020
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

numpy.ndarray.ndim() function return the number of dimensions of an array.

Syntax : numpy.ndarray.ndim(arr)

Parameters :
arr : [array_like] Input array. If it is not already an ndarray, a conversion is attempted.

Return : [int] Return the number of dimensions in arr.

Code #1 :




# Python program explaining
# numpy.ndarray.ndim() function
  
# importing numpy as geek 
import numpy as geek
  
arr = geek.array([1, 2, 3, 4])
  
gfg = arr.ndim
  
print (gfg)


Output :

1

 
Code #2 :




# Python program explaining
# numpy.ndarray.ndim() function
  
# importing numpy as geek 
import numpy as geek
  
arr = [[1, 2, 3], [4, 5, 6]]
  
gfg = geek.ndim(arr)
  
print (gfg)


Output :

2


Next Article

Similar Reads

NumPy ndarray itemset() Method | Insert Scalar in ndarray
The NumPy ndarray.itemset() method inserts a scalar into an array. Key Points:ndarray.itemset function needs at least one argument.The last argument you pass in the function is considered an "item". arr.itemset(*args) is a quicker way to do same thing as arr[args] = item. The item should be a scalar value and args must select a single item in the a
2 min read
NumPy ndarray.tolist() Method | Convert NumPy Array to List
The ndarray.tolist() method converts a NumPy array into a nested Python list. It returns the array as an a.ndim-levels deep nested list of Python scalars. Data items are converted to the nearest compatible built-in Python type. Example C/C++ Code import numpy as np gfg = np.array([1, 2, 3, 4, 5]) print(gfg.tolist()) Output[1, 2, 3, 4, 5] SyntaxSynt
1 min read
NumPy ndarray.size() Method | Get Number of Elements in NumPy Array
The ndarray.size() method returns the number of elements in the NumPy array. It works the same as np.prod(a.shape), i.e., the product of the dimensions of the array. Example C/C++ Code import numpy as np arr = np.zeros((3, 4, 2), dtype = np.complex128) gfg = arr.size print (gfg) Output : 24Syntax Syntax: numpy.ndarray.size(arr) Parameters arr : [ar
1 min read
NumPy ndarray.imag() Method | Get Imaginary Part in NumPy Array
The ndarray.imag() method returns the imaginary part of the complex number in the NumPy array. Note: Remember resulting data type for the imaginary value is 'float64'. Example C/C++ Code # import the important module in python import numpy as np # make an array with numpy gfg = np.array([1 + 2j, 2 + 3j]) # applying ndarray.imag() method geeks = np.
1 min read
NumPy ndarray.transpose() Method | Find Transpose of the NumPy Array
The ndarray.transpose() function returns a view of the array with axes transposed. For a 1-D array, this has no effect, as a transposed vector is simply the same vector.For a 2-D array, this is a standard matrix transpose.For an n-D array, if axes are given, their order indicates how the axes are permuted. If axes are not provided and arr.shape = (
2 min read
Python | Numpy numpy.ndarray.__lt__()
With the help of numpy.ndarray.__lt__() method of Numpy, We can find that which element in an array is less than the value which is provided in the parameter. It will return you numpy array with boolean type having only values True and False. Syntax: ndarray.__lt__($self, value, /) Return: self<value Example #1 : In this example we can see that
1 min read
Python | Numpy numpy.ndarray.__gt__()
With the help of numpy.ndarray.__gt__() method of Numpy, We can find that which element in an array is greater then the value which is provided in the parameter. It will return you numpy array with boolean type having only values True and False. Syntax: ndarray.__gt__($self, value, /) Return: self>value Example #1 : In this example we can see th
1 min read
Python | Numpy numpy.ndarray.__le__()
With the help of numpy.ndarray.__le__() method of Numpy, We can find that which element in an array is less than or equal to the value which is provided in the parameter. It will return you numpy array with boolean type having only values True and False. Syntax: ndarray.__le__($self, value, /) Return: self<=value Example #1 : In this example we
1 min read
Python | Numpy numpy.ndarray.__ge__()
With the help of numpy.ndarray.__ge__() method of Numpy, We can find that which element in an array is greater then or equal to the value which is provided in the parameter. It will return you numpy array with boolean type having only values True and False. Syntax: ndarray.__ge__($self, value, /) Return: self>=value Example #1 : In this example
1 min read
Python | Numpy numpy.ndarray.__ne__()
With the help of numpy.ndarray.__ne__() method of Numpy, We can find that which element in an array is not equal to the value which is provided in the parameter. It will return you numpy array with boolean type having only values True and False. Syntax: ndarray.__ne__($self, value, /) Return: self!=value Example #1 : In this example we can see that
1 min read
Python | Numpy numpy.ndarray.__neg__()
With the help of numpy.ndarray.__neg__() method of Numpy, one can multiply each and every element of an array with -1. Hence, the resultant array having values like positive values becomes negative and negative values become positive. Syntax: ndarray.__neg__($self, /) Return: -self Example #1 : In this example we can see that after applying numpy._
1 min read
Python | Numpy numpy.ndarray.__pos__()
With the help of numpy.ndarray.__pos__() method of Numpy, one can multiply each and every element of an array with 1. Hence, the resultant array having values same as original array. Syntax: ndarray.__pos__($self, /) Return: +self Example #1 : In this example we can see that after applying numpy.__pos__(), we get the simple array that can be the sa
1 min read
Python | Numpy numpy.ndarray.__sub__()
With the help of Numpy numpy.ndarray.__sub__(), We can subtract a particular value that is provided as a parameter in the ndarray.__sub__() method. Value will be subtracted to each and every element in a numpy array. Syntax: ndarray.__sub__($self, value, /) Return: self-value Example #1 : In this example we can see that each and every element in an
1 min read
Python | Numpy numpy.ndarray.__add__()
With the help of Numpy numpy.ndarray.__add__(), we can add a particular value that is provided as a parameter in the ndarray.__add__() method. Value will be added to each and every element in a numpy array. Syntax: ndarray.__add__($self, value, /) Return: self+value Example #1 : In this example we can see that each and every element in an array is
1 min read
Python | Numpy numpy.ndarray.__floordiv__()
With the help of Numpy numpy.ndarray.__floordiv__(), one can divide a particular value that is provided as a parameter in the ndarray.__floordiv__() method. Value will be divided to each and every element in a numpy array and remember it always gives the floor value after division. Syntax: ndarray.__floordiv__($self, value, /) Return: self//value E
1 min read
Python | Numpy numpy.ndarray.__mod__()
With the help of Numpy numpy.ndarray.__mod__(), every element in an array is operated on binary operator i.e mod(%). Remember we can use any type of values in an array and value for mod is applied as the parameter in ndarray.__mod__(). Syntax: ndarray.__mod__($self, value, /) Return: self%value Example #1 : In this example we can see that value tha
1 min read
Python | Numpy numpy.ndarray.__divmod__()
With the help of Numpy numpy.ndarray.__divmod__() method, we will get two arrays one is having elements that is divided by value that is provided in numpy.ndarray.__divmod__() method and second is having elements that perform mod operation with same value as provided in numpy.ndarray.__divmod__() method. Syntax: ndarray.__divmod__($self, value, /)
1 min read
Python | Numpy numpy.ndarray.__rshift__()
With the help of numpy.ndarray.__rshift__() method, we can get the elements that is right shifted by the value that is provided as a parameter in numpy.ndarray.__rshift__() method. Syntax: ndarray.__rshift__($self, value, /) Return: self>>value Example #1 : In this example we can see that every element is right shifted by the value that is pa
1 min read
Python | Numpy numpy.ndarray.__lshift__()
With the help of Numpy numpy.ndarray.__lshift__() method, we can get the elements that is left shifted by the value that is provided as a parameter in numpy.ndarray.__lshift__() method. Syntax: ndarray.__lshift__($self, value, /) Return: self<<value Example #1 : In this example we can see that every element is left shifted by the value that i
1 min read
Python | Numpy numpy.ndarray.__imul__()
With the help of numpy.ndarray.__imul__() method, we can multiply a particular value that is provided as a parameter in the ndarray.__imul__() method. Value will be multiplied to every element in a numpy array. Syntax: ndarray.__imul__($self, value, /)Return: self*=value Example #1 : In this example we can see that each and every element in an arra
1 min read
Python | Numpy numpy.ndarray.__isub__()
With the help of numpy.ndarray.__isub__() method, we can subtract a particular value that is provided as a parameter in the ndarray.__isub__() method. Value will be subtracted to every element in a numpy array. Syntax: ndarray.__isub__($self, value, /) Return: self-=value Example #1 : In this example we can see that each and every element in an arr
1 min read
Python | Numpy numpy.ndarray.__iadd__()
With the help of numpy.ndarray.__iadd__() method, we can add a particular value that is provided as a parameter in the ndarray.__iadd__() method. Value will be added to every element in a numpy array. Syntax: ndarray.__iadd__($self, value, /) Return: self+=value Example #1 : In this example we can see that each and every element in an array is adde
1 min read
Python | Numpy numpy.ndarray.__xor__()
With the help of Numpy numpy.ndarray.__xor__() method, we can get the elements that is XOR by the value that is provided as a parameter in numpy.ndarray.__xor__() method. Syntax: ndarray.__xor__($self, value, /) Return: self^value Example #1 : In this example we can see that every element is xor by the value that is passed as a parameter in ndarray
1 min read
Python | Numpy numpy.ndarray.__and__()
With the help of Numpy numpy.ndarray.__and__() method, we can get the elements that is anded by the value that is provided as a parameter in numpy.ndarray.__and__() method. Syntax: ndarray.__and__($self, value, /) Return: self&value Example #1 : In this example we can see that every element is anded by the value that is passed as a parameter in
1 min read
Python | Numpy numpy.ndarray.__or__()
With the help of Numpy numpy.ndarray.__or__() method, we can get the elements that is OR by the value that is provided as a parameter in numpy.ndarray.__or__() method. Syntax: ndarray.__or__($self, value, /) Return: self|value Example #1 : In this example we can see that every element is or by the value that is passed as a parameter in ndarray.__or
1 min read
Python | Numpy numpy.ndarray.__invert__()
With the help of Numpy numpy.ndarray.__invert__(), one can invert the elements of an array. We don't have to provide any type of parameter but remember that this method only works for integer values. Syntax: ndarray.__invert__($self, /) Return: ~self Example #1 : In this example we can see that every element in an array is operated on a unary opera
1 min read
Python | Numpy numpy.ndarray.__pow__()
With the help of Numpy numpy.ndarray.__pow__() method, we will get all the elements powered with the value that is provided as a parameter in numpy.ndarray.__pow__() method. Syntax: ndarray.__pow__($self, value, mod=None, /) Return: pow(self, value, mod) Example #1 : In this example we can see that every element get powered with the value that is p
1 min read
Python | Numpy numpy.ndarray.__truediv__()
With the help of Numpy numpy.ndarray.__truediv__(), we can divide a particular value that is provided as a parameter in the ndarray.__truediv__() method. Value will be divided to each and every element in a numpy array. Syntax: ndarray.__truediv__($self, value, /) Return: self/value Example #1 : In this example, we can see that each element in an a
1 min read
NumPy ndarray.__abs__() | Find Absolute Value of Elements in NumPy Array
The ndarray.__abs__() method returns the absolute value of every element in the NumPy array. It is automatically invoked when we use Python's built-in method abs() on a NumPy array. Example C/C++ Code import numpy as np gfg = np.array([1.45, 2.32, 3.98, 4.41, 5.55, 6.12]) print(gfg.__abs__()) Output[ 1 2 3 4 5 6] SyntaxSyntax: ndarray.__abs__() Ret
1 min read
NumPy ndarray.__ilshift__() | Shift NumPy Array Elements to Left
The ndarray.__ilshift__() method is an in-place left-shift operation. It shifts elements in the array to the left of the number of positions specified. Example C/C++ Code import numpy as np gfg = np.array([1, 2, 3, 4, 5]) # applying ndarray.__ilshift__() method print(gfg.__ilshift__(2)) Output[ 4 8 12 16 20] SyntaxSyntax: ndarray.__ilshift__($self,
1 min read
  翻译: