Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Numpy array dimensions

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 a (e.g.a is a 2 by 2 array)?

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

like image 857
morgan freeman Avatar asked Jun 17 '10 12:06

morgan freeman


People also ask

What is 3 dimensional NumPy array?

Numpy provides a function that allows us manipulate data that can be accessed. A three dimensional means we can use nested levels of array for each dimension. To create a 3-dimensional numpy array we can use simple numpy. array() function to display the 3-d array.

What is a 2 dimensional NumPy array?

2D array are also called as Matrices which can be represented as collection of rows and columns. In this article, we have explored 2D array in Numpy in Python. NumPy is a library in python adding support for large multidimensional arrays and matrices along with high level mathematical functions to operate these arrays.

Can NumPy arrays have more than 2 dimensions?

Creating arrays with more than one dimensionIn general numpy arrays can have more than one dimension. One way to create such array is to start with a 1-dimensional array and use the numpy reshape() function that rearranges elements of that array into a new shape.

How do you create a 2 dimensional NumPy array?

In Python to declare a new 2-dimensional array we can easily use the combination of arange and reshape() method. The reshape() method is used to shape a numpy array without updating its data and arange() function is used to create a new array.


1 Answers

It is .shape:

ndarray.shape
Tuple of array dimensions.

Thus:

>>> a.shape (2, 2) 
like image 144
Felix Kling Avatar answered Sep 29 '22 11:09

Felix Kling