forked from china-testing/python-api-tesing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecord.py
More file actions
executable file
·27 lines (20 loc) · 762 Bytes
/
record.py
File metadata and controls
executable file
·27 lines (20 loc) · 762 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import numpy as np
# Chapter 2 Beginning with NumPy fundamentals
#
# Demonstrates the NumPy record data type.
#
# Run from the commandline with
#
# python record.py
print("In: t = dtype([('name', numpy.str_, 40), ('numitems', numpy.int32), ('price', numpy.float32)])")
t = np.dtype([('name', np.str_, 40), ('numitems', np.int32), ('price', np.float32)])
print(t)
#Out: dtype([('name', '|S40'), ('numitems', '<i4'), ('price', '<f4')])
print("In: t['name']")
print(t['name'])
#Out: dtype('|S40')
print("In: itemz = array([('Meaning of life DVD', 42, 3.14), ('Butter', 13, 2.72)], dtype=t)")
itemz = np.array([('Meaning of life DVD', 42, 3.14), ('Butter', 13, 2.72)], dtype=t)
print("In: itemz[1]")
print(itemz[1])
#Out: ('Butter', 13, 2.7200000286102295)