Say I have a variable which is assigned the type 'long'
x = 40*2*10**30
If I then attempt to take the log of this variable using numpy (imported as np):
np.log10(x)
I am faced with an attribute error:
'long' object has no attribute 'log10'.
To get around this I can make the variable a float and it works just fine or use the 'math' package:
math.log10(x)
np.log10(float(x))
My question is: how does math.log10 and np.log10 differ and why is np not set up to handle 'long' types?
So, what I mean by this is that if your working with a number range from 100 to 200 you could use the Unit8 data type because it covers all the integers from 0 to 255.
size: This attribute calculates the total number of elements present in the NumPy array.
In Python 2, an int is a C long, and a long is like BigInterger in Java, it's a type that can hold any size of integer (it allocates memory if it's too big) – Cilyan.
Character code 'B' Alias on this platform (Linux x86_64) numpy. uint8: 8-bit unsigned integer (0 to 255). Most often this is used for arrays representing images, with the 3 color channels having small integer values (0 to 255). Follow this answer to receive notifications. answered Jul 15, 2021 at 2:41.
The problem is that numpy is written in C and it does not have a data type that can handle a number as large as the regular python int class. If you go here: http://docs.scipy.org/doc/numpy/user/basics.types.html it explains the different data types allowed in numpy. Take special note of the int64 dtype, the largest numbers allowed in that type are much smaller than the integer number that you have input. However float64 (which is equivalent to double in C) can handle up to an 11 bit exponent, which is why when you convert to float there is no overflow error.
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