"""
    查看数据类型并修改操作
"""
 
import numpy as np
print("--------------常用数据类型----------------")
# 默认整数int32,小数float64
a = np.array([1, 1, 1])
b = np.array([1., 1, 1])
c = np.array([1, 1, 1], dtype=np.float32)
d = np.array([1, 1, 1], dtype=np.string_)
print("整型:", a.dtype)
print("浮点数:", b.dtype)
print("浮点数:", c.dtype)
print("字节数组:", d.dtype)
 
print("--------------数据类型修改----------------")
a = np.array([1, 2, 3, 4, 5])
print("字节数组:", a.tostring())
print("浮点数:", a.astype(np.float32))
 

 

整型: int32
浮点数: float64
浮点数: float32
字节数组: |S1
--------------数据类型修改----------------
字节数组: b'\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x04\x00\x00\x00\x05\x00\x00\x00'
浮点数: [1. 2. 3. 4. 5.]
 
 

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-14
  • 2021-09-09
  • 2021-09-02
  • 2022-12-23
猜你喜欢
  • 2021-05-17
  • 2022-12-23
  • 2021-08-29
  • 2021-12-01
  • 2021-11-17
  • 2021-10-01
相关资源
相似解决方案