をリストを書くとき、私はサイズの行列X(n*n
)を持っている(つまり、条件を満たした行のN/2は、ファイルに移動しなければなりません他に残っている)。私は、次のコードのようにそれを書いた:問題バイナリファイルに
def write_to_binary_file(X, y):
posiResponse = []
negaResponse = []
for idx, res in enumerate(y):
if res == 1:
posiResponse.extend(X[idx])
else:
negaResponse.extend(X[idx])
with open("POS.bin", mode='wb') as file1:
file1.write(bytearray(posiResponse))
file1.close()
with open("NEG.bin", mode='wb') as file2:
file2.write(bytearray(negaResponse))
file2.close()
私は配列文句エラーを取得し、どのように私はbytearray()
を使用しますが、私はそれを微調整する方法がわからない:
Traceback (most recent call last):
File "exper.py", line 173, in <module>
write_data(X, y)
File "exper.py.py", line 47, in write_data
file1.write(bytearray(posiResponse))
TypeError: an integer or string of size 1 is required
親切に、することができます誰かが良い修正を提供していますか?ありがとうございました。
あなたは、バイナリファイルにnumpyの配列を作成しようとしていますか?それがどうやって気になりますか? –