item for item in numpy.ndarray

I have a numpy.ndarray Datasets which in the debug window looks like array([['13.234.... This array can have several million elements in it and I'm trying to filter it down and then randomise the order of the filtered data.

On the line RandomRows = ReducedList[RandomIndicies] I get the error only integer scalar arrays can be converted to a scalar index. From what I can see the ReducedList I'm generating is coming out in a different format [array(['13.234... and I can't figure out how to change this.

This is the code I have...

SearchRadUpper1 = 10
SearchRadUpper2 = 15

ReducedList = [Item for Item in DataSets[:] if math.sqrt((((float(Item[0]))**2) + ((float(Item[1]))**2) + ((float(Item[2]))**2))) <= SearchRadUpper1 \
    or math.sqrt((((float(Item[0]))**2) + ((float(Item[1]))**2) + ((float(Item[2]))**2))) <= SearchRadUpper2]

RandomIndices = RandomGenerator.integers(
    low=0, high=len(ReducedList), size=Count)

RandomRows = ReducedList[RandomIndices]

Any help would be much appreciated.


If want to filter your array, there is no need for iterating. You can instead try

SearchRadUpper1 = 10

idx = np.where((np.linalg.norm(DataSets, axis=1) <= SearchRadUpper1))
ReducedList = DataSets[idx]

Count = 100
random_idx = np.random.choice(range(len(ReducedList, Count)))
RandomRows = ReducedList[random_idx]

Also it seems like your criteria of Item <= SearchRadUpper1 or Item <= SearchRadUpper2 is not necessary as the first statement is always true if the second is true.