NumPy in Python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

NumPy in Python

In an online article the following statement is mentioned "Here, we have specified dtype to 32 bits (4 bytes). Hence, this array can take values from -2-31 to 2-31-1 " ones_array = np.ones( (1, 5), dtype=np.int32 ) What does it signifies ? How it can be represented via input/output ? Also if it is ones array then its values should be all set to 1 then how can we achieve different values ?

4th Jun 2019, 10:01 PM
harshit
harshit - avatar
1 Answer
+ 1
What do you mean by "represented via input/output"? np.ones((1,5)) creates an array containing only ones, with array size 1x5. You can print it to see the result. print(ones_array) dtype only specifies the data types. That means you can store integers from the range stated in the text. Of course np.ones will only give you ones, but you can alter the array afterwards. Like ones_array[3] = 28272
5th Jun 2019, 12:55 PM
Matthias
Matthias - avatar