Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

I'm currently trying to learn Numpy and Python. Given the following array:

import numpy as np

a = np.array([[1,2],[1,2]])

Is there a function that returns the dimensions of an (e.g.a is a 2 by 2 array)?

size() returns 4 and that doesn't help very much.

1 Answer

0 votes
by (106k points)

To get Numpy array’s dimensions you can use shape() function. The output of the dimension will be in the form of the tuple:

An example that shows how to do it:-

import numpy as np

a = np.array([[1,2],[1,2]])

a.shape

image

Related questions

0 votes
4 answers
0 votes
2 answers
0 votes
1 answer
0 votes
1 answer

Browse Categories

...