回答編集履歴
1
追記
test
CHANGED
@@ -13,3 +13,59 @@
|
|
13
13
|
np.savetxt('test.dat', data, fmt='%d')
|
14
14
|
|
15
15
|
```
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
コメントを受けて
|
20
|
+
|
21
|
+
---
|
22
|
+
|
23
|
+
> ついでにですが以下のようなデータも保存できますでしょうか。
|
24
|
+
|
25
|
+
ぜひ教えていただけると助かります。
|
26
|
+
|
27
|
+
> ```
|
28
|
+
|
29
|
+
# test.txtの中身
|
30
|
+
|
31
|
+
100
|
32
|
+
|
33
|
+
200
|
34
|
+
|
35
|
+
300
|
36
|
+
|
37
|
+
1 1 1 1 1 1 1 1 1 1
|
38
|
+
|
39
|
+
...
|
40
|
+
|
41
|
+
> ```
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
それだとprintを使うと楽でしょう。
|
46
|
+
|
47
|
+
```Python
|
48
|
+
|
49
|
+
import numpy as np
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
data = np.full((10, 10), 1, dtype=np.int)
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
with open('test.txt', mode='w') as fout:
|
58
|
+
|
59
|
+
print(100, file=fout)
|
60
|
+
|
61
|
+
print(200, file=fout)
|
62
|
+
|
63
|
+
print(300, file=fout)
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
for row in data:
|
68
|
+
|
69
|
+
print(*row, file=fout)
|
70
|
+
|
71
|
+
```
|