Quansight-Labs / numpy.net

A port of NumPy to .Net
BSD 3-Clause "New" or "Revised" License
131 stars 14 forks source link

about slicing #13

Closed BackT0TheFuture closed 3 years ago

BackT0TheFuture commented 3 years ago
a = np.load('./sample.npy') # (10,10,3)
R = img[:, :, 0]
G = img[:, :, 1]
B = img[:, :, 2]
print(R.shape,G.shape,B.shape)
(10, 10) (10, 10) (10, 10)
imgnd # (10,10,3)
var r = (ndarray)imgnd[":", ":", "0"];
var g = (ndarray)imgnd[":", ":", "1"];
var b = (ndarray)imgnd[":", ":", "2"];
 Console.WriteLine($"{r.shape}   {g.shape}   {b.shape}");
(10, 10, 3)   (10, 10, 2)   (10, 10, 1)

Was I wrong about slicing via C#? thanks!

KevinBaselinesw commented 3 years ago

Try one of these forms instead. I am interpreting the "0", as "new Slice(0)" instead of as an index which takes a different path.

       var r = (ndarray)imgnd[":", ":", 0];
        var g = (ndarray)imgnd[":", ":", 1];
        var b = (ndarray)imgnd[":", ":", 2];

        r = imgnd.A(":", ":", 0);
        g = imgnd.A(":", ":", 1);
        b = imgnd.A(":", ":", 2);
BackT0TheFuture commented 3 years ago

both of two work correctly. thank you so much!