如何使用mir.ndslice按D中的列值选择行?
我正在浏览文档,试图找出如何按列进行简单的行选择 在努比,我会做:如何使用mir.ndslice按D中的列值选择行?,d,mir,D,Mir,我正在浏览文档,试图找出如何按列进行简单的行选择 在努比,我会做: 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 whe
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]])
使用mir库,我天真地尝试:
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];
但是得到
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.
因此,我浏览了文档,没有找到任何看起来像
np.where
或类似的内容。甚至在和平号中也有可能吗 从未使用过mir,但D范围在此处可用(即过滤器!(行=>行[2]>10)
)?使用std.algorithm.filter
可以很好地处理mir切片。只是想知道是否只有和平号有这样的设施。