Skip to content

Commit bab1db7

Browse files
committed
commit
1 parent 485f014 commit bab1db7

File tree

8 files changed

+109
-29
lines changed

8 files changed

+109
-29
lines changed

.idea/workspace.xml

Lines changed: 43 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python科学计算基础/Numpy数据存取与常用函数.py

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,53 @@
2424

2525
# b1 = np.loadtxt('a1.csv', delimiter=',')
2626
# print(b1)
27-
b2 = np.loadtxt('a2.csv', delimiter=',')
28-
print(b2)
27+
# b2 = np.loadtxt('a2.csv', dtype=np.int, delimiter=',')
28+
# print(b2)
29+
30+
'''CSV只能有效存储一维和二维数组,np.savetxt() np.loadtxt()只能有效存取一维和二维数组'''
31+
32+
"""
33+
多维数据的存取(字符串与二进制的数据写入读取)
34+
"""
35+
# 二进制更节省储存空间 这个和编码有关系
36+
37+
# a.tofile(frame, sep='', format='%s')
38+
# • frame  : 文件、字符串
39+
# • sep : 数据分割字符串,如果是空串,写入文件为二进制
40+
# • format : 写入数据的格式
41+
42+
# a = np.arange(100).reshape(5, 10, 2)
43+
# a.tofile('b.dat', sep=',', format='%d')
44+
# a.tofile('c.bat', format='%d')
45+
46+
47+
# np.fromfile(frame, dtype=float, count=‐1, sep='')
48+
# • frame  : 文件、字符串
49+
# • dtype : 读取的数据类型
50+
# • count  : 读入元素个数,‐1表示读入整个文件
51+
# • sep : 数据分割字符串,如果是空串,写入文件为二进制
52+
53+
# a1 = np.fromfile('b.dat', dtype=np.int, sep=',').reshape(5, 10, 2)
54+
# print(a1)
55+
# a2 = np.fromfile('c.bat', dtype=np.int).reshape(5, 10, 2)
56+
# print(a2)
57+
58+
'''
59+
注意事项:
60+
该方法需要读取时知道存入文件时数组的维度和元素类型
61+
a.tofile()和np.fromfile()需要配合使用
62+
可以通过元数据文件来存储额外信息
63+
'''
64+
65+
"""
66+
numpy的便捷文件存取
67+
"""
68+
69+
# np.save(fname, array) 或 np.savez(fname, array)
70+
# • fname : 文件名,以.npy为扩展名,压缩扩展名为.npz
71+
# • array  : 数组变量
72+
# np.load(fname)
73+
# • fname : 文件名,以.npy为扩展名,压缩扩展名为.npz
74+
75+
a = np.arange(100).reshape(5, 10, 2)
76+
np.save('a.npy', a)

Python科学计算基础/a.csv

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19
2+
20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39
3+
40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59
4+
60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79
5+
80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99

Python科学计算基础/a.npy

480 Bytes
Binary file not shown.

Python科学计算基础/a1.csv

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19
2+
20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39
3+
40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59
4+
60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79
5+
80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99

Python科学计算基础/a2.csv

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0
2+
20.0,21.0,22.0,23.0,24.0,25.0,26.0,27.0,28.0,29.0,30.0,31.0,32.0,33.0,34.0,35.0,36.0,37.0,38.0,39.0
3+
40.0,41.0,42.0,43.0,44.0,45.0,46.0,47.0,48.0,49.0,50.0,51.0,52.0,53.0,54.0,55.0,56.0,57.0,58.0,59.0
4+
60.0,61.0,62.0,63.0,64.0,65.0,66.0,67.0,68.0,69.0,70.0,71.0,72.0,73.0,74.0,75.0,76.0,77.0,78.0,79.0
5+
80.0,81.0,82.0,83.0,84.0,85.0,86.0,87.0,88.0,89.0,90.0,91.0,92.0,93.0,94.0,95.0,96.0,97.0,98.0,99.0

Python科学计算基础/b.dat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0,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,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99

Python科学计算基础/c.bat

400 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)