-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumpy_ndarray+attribute.py
More file actions
63 lines (47 loc) · 885 Bytes
/
numpy_ndarray+attribute.py
File metadata and controls
63 lines (47 loc) · 885 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import numpy as np
#get shape of ndarray
#(row, column)
a = np.array([[1,2,3],[4,5,6]])
print a.shape
#change ndarray shape
b = np.array([[1,2,3],[4,5,6]])
b.shape = (3,2)
print b
#get ndim of ndarray
c = np.arange(24)
c.shape = (4,6)
print c.ndim
print c
#get itemsize of ndarray
d = np.array([1,2,3,4,5])
print d.itemsize
#get flags of ndarray
e = np.array([1,2,3,4,5])
print e.flags
#the empty of ndarray
f = np.empty([4,6], dtype = int)
print f
#the zeros of ndarray
g = np.zeros((5,6), dtype = int)
print g
#the ones of ndarray
h = np.ones((2,3), dtype = float)
print h
#-----------------
#
# ndarray data from there
#
#-----------------
#asarray
x = [1,2,3]
A = np.asarray(x, dtype = int)
print A
#frombuffer
tmp = 'Hello Man'
B = np.frombuffer(tmp, dtype = 'S1')
print B
#fromiter
tmpList = range(6)
it = iter(tmpList)
C = np.fromiter(it, dtype = int)
print C