Can anyone please help me to understand that from where does Numpy's array function infers data type.
I understand it basically infers from the kind of value that has been assigned to the array.
For Example:
> data = [1,2,3,4]
> arr = np.array(data)
So in the above lines the "arr" will have the dtype('int64')
or dtype('int32')
.
What I am trying to understand is how does it decides whether to give it a int64
or a int32
?
I understand that it might be a trivial question but I am just trying to understand that how does it work as I was recently asked this in an interview.
Numeric data types include integers and floats.
If we have an array that contains both integers
and floating point numbers
, numpy
will assign the entire array to the float
data type so the decimal points are not lost.
An integer will never have a decimal point. So for example, 2.55 would be stored as 2
As mentioned by @unutbu int32
and int64
depends on the type of bit-machines you have, whether it is a 32 bit-machine or a 64 bit-machine
Strings
, are values that contain numbers
and/or characters
. For example, a string might be a word, a sentence, or several sentences. The most general dtype=string
will be assigned to your array if your array has mixed types (numbers and strings).
To have a complete detailed look, you can have a look at this website of scipy docs
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