I'm trying the functions of numpy arrays and below is the code:
import numpy as np
Z =np.array(
[[0,4,0,0,0,0],
[0,0,0,1,0,0],
[0,1,0,1,0,0],
[0,0,1,1,0,0],
[0,0,0,0,0,0],
[0,0,0,0,0,0]])
print Z
print Z.dtype
print Z.shape
Which gave:
[[0 4 0 0 0 0]
[0 0 0 1 0 0]
[0 1 0 1 0 0]
[0 0 1 1 0 0]
[0 0 0 0 0 0]
[0 0 0 0 0 0]]
int32
(6L, 6L)
It is an integer array with 6 rows and 6 columns. But what is the 32 from numpy.type and the L in numpy.shape?
The shape of an array is the number of elements in each dimension. NumPy arrays have an attribute called shape that returns a tuple with each index having the number of corresponding elements.
It is an integer array with 6 rows and 6 columns. But what is the 32 from numpy.type and the L in numpy.shape? Show activity on this post. The 32 in the array type refers to 32-bit width of the underlying machine integer that stores the array.
Python numpy shape 0 In this section, we will discuss Python NumPy shape 0. Shape is n.shape is a tuple that always gives dimensions of the array. The shape is a tuple that gives you an indication of the no. of dimensions in the array.
In numpy arrays we use the same data type, numpy arrays provide numeric data type to draw an array. But numpy provides a facility to include explicitly data types. In the above example, dtype gives the data type of the array as int64. Similarly, it is also giving float 64 as a data type in the next example of numpy.
The 32 in the array type refers to 32-bit width of the underlying machine integer that stores the array. This means that an array with, say, 1 million elements, will take up at least 4 million bytes (32 million bits) of memory.
On the other hand, the suffix L
returned by the shape
property has nothing to do with the data you can put in your arrays and you should not be concerned with it. If you are interested in the techical details, L
denotes the long
Python type used to represent integers of unbounded width (not to be confused with the C type of the same name). It doesn't make much sense to represent a small integer such as the number 6 as long
, but some code does it anyway for consistency with the same API returning a larger integer. For example, the os.stat
call always returns byte sizes in long integers, even if they would fit the regular int
type, in order to maintain type invariance of its return value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With