numpy 数据类型转化

查看数据类型:dtype

例子1:

In[1]: a = np.arange(5)
In[2]: a.dtype
Out[1]:  dtype('int32')

例子2:

In[1]: b = np.array([1.00, 2.00 ,3.00 ,4.00 ], dtype=np.float64)
In[2]: b.dtype
Out[1]: dtype('float64')

数据转换:astype

例子1:

In[1]: a = a.astype(np.float64)
In[1]: a.dtype
Out[1]: dtype('float64')

例子2:

In[1]: b = b.astype(np.int32)
In[2]: b.dtype
Out[2]: dtype('int32')
posted @ 2022-07-22 19:07  CharlesLC  阅读(328)  评论(0)    收藏  举报