python - Data type for numpy.random -


why following numpy.random command not return array data type of 'int' understand should happen documentation.

import numpy  b = numpy.random.randint(1,100,10,dtype='int')  type(b[1])  class 'numpy.int64' 

i can't change type using .astype() either.

numpy uses it's own int types, since python (3) int can of arbitrary size. in other words, can't have array of python ints, best can object dtype. observe:

in [6]: x = np.array([1,2,3],dtype=np.dtype('o'))  in [7]: x[0] out[7]: 1  in [8]: type(x[0]) out[8]: int  in [9]: x2 = np.array([1,2,3],dtype=int)  in [10]: x2 out[10]: array([1, 2, 3])  in [11]: x2[0] out[11]: 1  in [12]: type(x2[0]) out[12]: numpy.int64 

Comments

Popular posts from this blog

c# SetCompatibleTextRenderingDefault must be called before the first -

C#.NET Oracle.ManagedDataAccess ConfigSchema.xsd -

c++ - Fill runtime data at compile time with templates -