I was used to Matlab, so when I want to create an array of 10**j in Python, where j is an integer, I use the following code:
import numpy as np
a=np.array(range(11))
b=10**a
However my machine gives me the following output:
array([ 1, 10, 100, ..., 100000000,
1000000000, -2147483648], dtype=int32)
The last entry is obviously wrong. Now, I know I can do the following
b=np.array([10**k for k in range(11)])
which gives the correct answer, so I guess the problem is from the numpy function array (Of course, I can avoid this problem by saving a as a int64 integer, but there will be overflow problem for larger j). It seems like there could be a lot of situations where one could fall into this pitfall of overflowed integers when doing mathematical operations on arrays. I am wondering whether there are ways to avoid this problem?
np.arange(11, dtype='int32')