Detect number of dimensions of numpy array (not shape)

develarist

Getting the shape of two different numpy arrays returns tuples

a.shape
Out[131]: (3,)

A.shape
Out[132]: (3, 3)

Based on the tuples, one is a one-dimensional array (number of dimensions = 1), the other is 2d. How can I detect number of dimensions similar to how type(A) will tell me one of them is a numpy.ndarray? should I just use len(a.shape)?

black

You should use numpy.ndarray.ndim. So

a.ndim # gives 1

and

A.ndim # gives 2

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Get an image from a 4 dimensions Numpy array as a 4 dimensions Numpy array

分類Dev

Average of X*Y items and keeping dimensions of the numpy array

分類Dev

Slicing NumPy array given start and end indices for generic dimensions

分類Dev

block mean of 2D numpy array (in both dimensions)

分類Dev

Replace a string numpy array with a number

分類Dev

LSTM network expects target at last layer to have 2 dimensions, but got array with shape (996, 1, 1)

分類Dev

How can I create a numpy array with shape (0, 2)?

分類Dev

Numpy.Append(): ValueError: could not broadcast input array from shape (4) into shape (3)

分類Dev

Error when checking target: expected time_distributed_5 to have 3 dimensions, but got array with shape (14724, 1)

分類Dev

Can I combine non-adjacent dimensions in a NumPy array without copying data?

分類Dev

How to update a numpy array based on a masked array w/ same dimension and shape

分類Dev

How to index a numpy array of dimension N with a 1-dimensional array of shape (N,)

分類Dev

Rounding elements in numpy array to the number of the same index in another array

分類Dev

Append numpy arrays with different dimensions

分類Dev

Redim variable number of dimensions in VBA

分類Dev

Lasagne/Theano wrong number of dimensions

分類Dev

Count the number of non zero values in a numpy array in Numba

分類Dev

Numpy.shape関数

分類Dev

Frame an image: How to make a shape's dimensions fit around an image?

分類Dev

Groovy filter two dimensions array

分類Dev

Is it possible to squeeze all but N dimensions using numpy?

分類Dev

NumPyのx.shape [0]とx [0] .shape

分類Dev

Resizing an array to another shape in Python

分類Dev

Fast numpy covariance for arrays of different shape

分類Dev

Numpy function to get shape of added arrays

分類Dev

What are dimensions in multi dimensional array in practical sense

分類Dev

Windows Phone 8: C# XAML how to detect shape collisions

分類Dev

Get column number of elements that are greater than a threshold in 2D numpy array

分類Dev

How to covert array of shape n, to n,m

Related 関連記事

  1. 1

    Get an image from a 4 dimensions Numpy array as a 4 dimensions Numpy array

  2. 2

    Average of X*Y items and keeping dimensions of the numpy array

  3. 3

    Slicing NumPy array given start and end indices for generic dimensions

  4. 4

    block mean of 2D numpy array (in both dimensions)

  5. 5

    Replace a string numpy array with a number

  6. 6

    LSTM network expects target at last layer to have 2 dimensions, but got array with shape (996, 1, 1)

  7. 7

    How can I create a numpy array with shape (0, 2)?

  8. 8

    Numpy.Append(): ValueError: could not broadcast input array from shape (4) into shape (3)

  9. 9

    Error when checking target: expected time_distributed_5 to have 3 dimensions, but got array with shape (14724, 1)

  10. 10

    Can I combine non-adjacent dimensions in a NumPy array without copying data?

  11. 11

    How to update a numpy array based on a masked array w/ same dimension and shape

  12. 12

    How to index a numpy array of dimension N with a 1-dimensional array of shape (N,)

  13. 13

    Rounding elements in numpy array to the number of the same index in another array

  14. 14

    Append numpy arrays with different dimensions

  15. 15

    Redim variable number of dimensions in VBA

  16. 16

    Lasagne/Theano wrong number of dimensions

  17. 17

    Count the number of non zero values in a numpy array in Numba

  18. 18

    Numpy.shape関数

  19. 19

    Frame an image: How to make a shape's dimensions fit around an image?

  20. 20

    Groovy filter two dimensions array

  21. 21

    Is it possible to squeeze all but N dimensions using numpy?

  22. 22

    NumPyのx.shape [0]とx [0] .shape

  23. 23

    Resizing an array to another shape in Python

  24. 24

    Fast numpy covariance for arrays of different shape

  25. 25

    Numpy function to get shape of added arrays

  26. 26

    What are dimensions in multi dimensional array in practical sense

  27. 27

    Windows Phone 8: C# XAML how to detect shape collisions

  28. 28

    Get column number of elements that are greater than a threshold in 2D numpy array

  29. 29

    How to covert array of shape n, to n,m

ホットタグ

アーカイブ