numpy array using python's long type

前端 未结 1 923
轻奢々
轻奢々 2021-01-18 07:11

I am trying to create a numpy array with type long (that is, Python\'s long, not numpy\'s long = int64).

If I do:



        
相关标签:
1条回答
  • 2021-01-18 07:34

    Python's long integer type is not a native numpy type, so you will have to use the object data type. The elements of an numpy array with object type can be any python objects.

    For example,

    In [1]: x = np.array([1L, 2L, 3L], dtype=object)
    
    In [2]: x
    Out[2]: array([1L, 2L, 3L], dtype=object)
    
    In [3]: x[0]
    Out[3]: 1L
    
    In [4]: type(x[0])
    Out[4]: long
    

    Whether or not this is useful for you depends on what you want to do with the array of longs.

    0 讨论(0)
提交回复
热议问题