Next / Previous / Contents / Shipman's homepage

5.5. Array attributes

These attributes are available from any ndarray.

.ndim

The number of dimensions of this array.

.shape

A tuple of the array's dimensions.

.dtype

The array's type as a dtype instance.

>>> print d1
[ 2.4 -1.5  3.   8.8]
>>> print d1.ndim, d1.shape, d1.dtype
1 (4,) float64
>>> print d2
[[ 0  1  2  3]
 [ 4  5  6  7]
 [ 8  9 10 11]]
>>> print d2.ndim, d2.shape, d2.dtype
2 (3, 4) int32
>>> print d3
[[[ 0  1  2  3]
  [ 4  5  6  7]
  [ 8  9 10 11]]

 [[12 13 14 15]
  [16 17 18 19]
  [20 21 22 23]]]
>>> print d3.ndim, d3.shape, d3.dtype
3 (2, 3, 4) int32