I would like to index ndarray in a tuple using a boolean mask such as below
import numpy as np
n_max = 5
list_no = np.arange ( 0, n_max )
lateral = np.tril_indices ( n_max, -1 )
mask= np.diff ( lateral [0].astype ( int ) )
mask [-1] = 1
Expected=lateral[mask!= 0]
However, when executing the line Expected=lateral[mask!= 0],
the compiler return an error
TypeError: only integer scalar arrays can be converted to a scalar index
Expected=
0 = {ndarray: (4,)} [1 2 3 4]
1 = {ndarray: (4,)} [0 1 2 3]
May I know where did I do wrong?
lateral[mask!-0]lateral. You could even show the whole thing! Be generkus with the information. Good answers show results.