Skip to content Skip to sidebar Skip to footer

How To Rightly Locate A Value At An Index In Nd Array And Save It As List In Python?

I have a list called L. It has C number of elements. I have a nd array called X. X has Boolean data (either 0 or 1). It has dimension as (20,C). There are 20 lists with each list

Solution 1:

the last line should be:

empylist.append(L[index[0]])

and I don't see what your tuple_to_list is needed for

A solution using only arrays would be the following:

L = list(np.random.rand(20)) # gives a List of radom values (to be compatible to the question)La = np.array(L)
X = randint(0,5,(20,101)) # make an array having values from 0...4emptylist = La[np.where(X==1)[0]] #gives those rows of L where rows of X contain 1

though the name empty is not appropriate anymore.

Post a Comment for "How To Rightly Locate A Value At An Index In Nd Array And Save It As List In Python?"