ruby-numo / numo-narray

Ruby/Numo::NArray - New NArray class library
http://ruby-numo.github.io/narray/
BSD 3-Clause "New" or "Revised" License
415 stars 41 forks source link

How to access like Ruby each? #105

Closed naitoh closed 6 years ago

naitoh commented 6 years ago

As below, I want to use each array in the first dimension of a multidimensional array.

a.shape[0].times{|i| p a[i, false]}
Numo::DFloat(view)#shape=[2,2]
[[0, 1], 
 [2, 3]]
Numo::DFloat(view)#shape=[2,2]
[[4, 5], 
 [6, 7]]

Is there a way to write this more easily?

masa16 commented 6 years ago

How about NArray#each_over_axis ? https://github.com/ruby-numo/numo-narray/commit/2a5aae80805a4bba88e7bdb2919b7a9812d8838f Method name comes from numpy.apply_over_axes : https://docs.scipy.org/doc/numpy/reference/generated/numpy.apply_over_axes.html#numpy.apply_over_axes

naitoh commented 6 years ago

Thank you for your reply.

How about NArray#each_over_axis ?

I think it's good. I am glad if this can be used.

naitoh commented 6 years ago

I confirmed on numo-narray 0.9.1.3. Thank you new feature.