Skip to main content

Numpy: Create Higher Dimensional Arrays using ndmin()

As we know, an array can have any number of dimensions. If you want to create an array of higher dimensions, you can define the number of dimensions by using ndim() arguments.


import numpy as np
a=np.array([['a','b','c','d','e','f']], ndmin=6)
print('number of dimensions :', a.ndim)


[[[[[['a' 'b' 'c' 'd' 'e' 'f']]]]]]
number of dimensions : 6

In the above example, the output array has 6 elements in the innermost dimension i.e. 6th dim, 1 element in 5th dim i.e. the vector, 4th dim has 1 element i.e. matrix with vector, the 3rd dim has 1 element i.e. 3D array, the 2nd dim has 1 element i.e. 4D array, and 1st dim has 1 element i.e. a 5D array.
ndim() function also return the number of dimensions of an array.

Submitted by devanshi.srivastava on September 9, 2021

Devanshi, is working as a Data Scientist with iVagus. She has expertise in Python, NumPy, Pandas and other data science technologies.


At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.