2

I am browsing through mir.ndslice docs trying to figure out how to do a simple row selection by column.

In numpy I would do:

a = np.random.randint(0, 20, [4, 6])

# array([[ 8,  5,  4, 18,  1,  4],
#        [ 2, 18, 15,  7, 18, 19],
#        [16,  5,  4,  6, 11, 11],
#        [15,  1, 14,  6,  1,  4]])

a[a[:,2] > 10]  # select rows where the second column value is > 10
# array([[ 2, 18, 15,  7, 18, 19],
#        [15,  1, 14,  6,  1,  4]])

Using mir library I naively tried:

import std.range;
import std.random;
import mir.ndslice;

auto a = generate!(() => uniform(0, 20)).take(24).array.sliced(4,6);
// [[12, 19,  3, 10, 19, 11], 
//  [19,  0,  0, 13,  9,  1], 
//  [ 0,  0,  4, 13,  1,  2], 
//  [ 6, 19, 14, 18, 14, 18]]

a[a[0..$,2] > 10];

But got

 Error: incompatible types for `((ulong __dollar = a.length();) , a.opIndex(a.opSlice(0LU, __dollar), 2)) > (10)`: `Slice!(int*, 1LU, cast(mir_slice_kind)0)` and `int`
dmd failed with exit code 1.

So, I went through the docs and couldn't find anything that would look like np.where or similar. Is it even possible in mir?

minerals
  • 6,090
  • 17
  • 62
  • 107

0 Answers0