質問編集履歴

2

修正

2019/02/07 05:02

投稿

pekeuto
pekeuto

スコア19

test CHANGED
@@ -1 +1 @@
1
- pythonのエラー
1
+ どこが間違ってますか
test CHANGED
File without changes

1

誤字

2019/02/07 05:02

投稿

pekeuto
pekeuto

スコア19

test CHANGED
File without changes
test CHANGED
@@ -40,7 +40,7 @@
40
40
 
41
41
  import numpy as np
42
42
 
43
- from numpy.random import randint
43
+ import random
44
44
 
45
45
  # 乱数の初期化
46
46
 
@@ -56,9 +56,13 @@
56
56
 
57
57
  # n×m行列の各成分を0~5の値でランダムに満たしてください
58
58
 
59
- image = randint(0,6,(n,m))
59
+ image=np.random.randint(0,6,(m,n))
60
+
61
+
60
62
 
61
63
  return image
64
+
65
+
62
66
 
63
67
 
64
68
 
@@ -68,9 +72,7 @@
68
72
 
69
73
  # 与えられた行列の形を取得し、shapeに代入してください
70
74
 
71
- shape = np.shape(matrix)
75
+ shape=matrix.shape
72
-
73
-
74
76
 
75
77
  # 行列の各成分について、変更するかしないかをランダムに決めた上で
76
78
 
@@ -78,23 +80,21 @@
78
80
 
79
81
 
80
82
 
81
- for i in range(0,shape[0]):
83
+ for m in range(0,shape[0]):
82
84
 
83
- for j in range(1,shape[1]):
85
+ for n in range (0,shape[1]):
86
+
87
+ a=random.randint(0,2)
84
88
 
85
89
 
86
90
 
87
- matrix[i][j] = randint(0,6)
91
+ if a!=0:
88
92
 
93
+ matrix[m][n]=random.randint(0,5)
89
94
 
95
+ else :
90
96
 
91
- if randint(0,3)== 0:
92
-
93
- break;
94
-
95
- else:
96
-
97
- matrix[i][j]
97
+ matrix[m][n]
98
98
 
99
99
 
100
100
 
@@ -122,7 +122,7 @@
122
122
 
123
123
  # image1とimage2の差分を計算し、image3に代入してください
124
124
 
125
- image3 = image1 - image2
125
+ image3=image1-image2
126
126
 
127
127
  print(image3)
128
128
 
@@ -130,7 +130,7 @@
130
130
 
131
131
  # image3の各成分が絶対値である行列をもとめimage3に再代入してください
132
132
 
133
- image3 = np.abs(image3)
133
+ image3=np.abs(image3)
134
134
 
135
135
 
136
136