Web13 jan. 2024 · 你可以使用argwhere: import numpy as np board = [[1, 2, 0], [0, 0, 1], [2, 0, 1]] result = np.argwhere(np.array(board) == 0).tolist() 输出 [[0, 2], [1, 0], [1, 1], [2, 1]] 如果坐标必须是元组,你可以这样做: result = [tuple(coord) for coord in np.argwhere(np.array(board) == 0).tolist()] 输出 [(0, 2), (1, 0), (1, 1), (2, 1)] 2楼 Web11 feb. 2024 · 1、numpy.where的返回结果 numpy.where调用方式为numpy.where(condition,1,2) 满足条件的位置上返回结果1,不满足的位置上返回结果2 例 …
Numpyでwhere関数を使い条件に応じた処理をする方法 IT …
Web2 apr. 2024 · numpy.where関数で複数の条件を設定するにはブール演算子を使い,各条件をカッコ ()で囲むことで可能です. ・配列内の要素値が-2以下または2以上の場合は配列内の値はそのままで,違う場合は0にするプログラムを作成します. [IN] import numpy as np a =np.array ( [-3,-2,-1,0,1,2,3]) print (np.where ( (a<=-2) (a >=2) , a, 0 )) [OUT] [-3 -2 0 0 0 … does marijuana give dopamine
【python】numpy配列の特定の条件を満たす要素のインデックスを取得する - Ren
Web24 dec. 2024 · numpy.argwhere () function is used to find the indices of array elements that are non-zero, grouped by element. Syntax : numpy.argwhere (arr) Parameters : arr : [array_like] Input array. Return : [ndarray] Indices of elements that are non-zero. Indices are grouped by element. Code #1 : import numpy as geek in_arr = [ [ 2, 0, 7], [ 0, 5, 9]] Web14 okt. 2024 · Numpy.argwhere () function finds the indices of non-zero elements in a given input array. The function returns a new array with the indices of non-zero elements in a multi-dimensional, sorted format (one index per row). Syntax numpy.argwhere(arr) Parameters The np argwhere () function takes one parameter, arr, whose data type is … WebI want to pick indices of 1,2,3,12 and 13 with np.argwhere or np.where.In both cases following code is not working. Is there any way to do this using these two commands or … does marijuana give you a hangover