热线电话:13121318867

登录
2019-06-17 阅读量: 439
如何理解结构化数组的数据类型对象

具有结构化数组的数据类型对象数据类型对象对于创建结构化数组非常有用。结构化数组是包含不同类型数据的数组。可以在字段的帮助下访问结构化数组。

字段就像指定对象的名称。在结构化数组的情况下,dtype对象也将被构造。 

# Python program for demonstrating
# the use of fields
import numpy as np

# A structured data type containing a
# 16-character string (in field ‘name’) 
# and a sub-array of two 64-bit floating
# -point number (in field ‘grades’)

dt = np.dtype([('name', np.unicode_, 16),
('grades', np.float64, (2,))])

# Data type of object with field grades
print(dt['grades'])

# Data type of object with field name 
print(dt['name'])

输出:

('<f8',(2,))
37.5000
1
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子