The file is loaded from the file in the form: [[1,2,3,4], [5,6,7,8]..] .
How to filter it, for example, by the third element of each internal array?
The file is loaded from the file in the form: [[1,2,3,4], [5,6,7,8]..] .
How to filter it, for example, by the third element of each internal array?
Example:
In [199]: a = np.arange(40).reshape(-1, 4) In [200]: a Out[200]: array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11], [12, 13, 14, 15], [16, 17, 18, 19], [20, 21, 22, 23], [24, 25, 26, 27], [28, 29, 30, 31], [32, 33, 34, 35], [36, 37, 38, 39]]) we leave only those rows in which the elements of the third column (with index 2 ) are divided by 3 without a remainder:
In [201]: a[a[:, 2] % 3 == 0] Out[201]: array([[ 4, 5, 6, 7], [16, 17, 18, 19], [28, 29, 30, 31]]) Source: https://ru.stackoverflow.com/questions/822599/
All Articles