-1
[[1,0,0,1]]のような数値配列があります。 Iは1と0の間の配列の特定のインデックスで値を切り替えるには、以下の方法を書いた:だからPython - 1と0の間のインデックスにある配列のスイッチ値を変更します。
'''
@param array: The array from which an value should be inverted
@param index: index at which the value should be inverted
'''
def change_binary_value(array, index):
if array[index]==0:
array[index] = 0
else:
array[index] = 1
、私のpythonの日常のユーザーではないと私は、このエラーを取得:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
まあ、私はany()またはall()を使いたくありません。私はちょうど単一の値を変更したい。なぜpythonは私にそれをしたいのですか?それは少し奇妙です。迅速な回答を望ん
、
ファビアン
このコードはそのエラーを生成しません... –
はまた、あなたがに0を割り当てる何を期待しています変数はすでに0のときに行うのですか? – kindall
@JoranBeasley私は正確にそのエラーを取得します。 –