reject_row, select_row, etc. methods
lokeshh opened this issue · 5 comments
The following methods will be very useful:
reject_row
,select_row
: When you want to filter rows given a condition.map_row
: To apply a function to every row.
Similarly for columns.
Applying a function on a row when a given condition is satisfied by the row is a commonly encountered thing. How can we deal with it? @zverok
Are you suggesting something like subsequent operations of filter
and map
? If this functionality isn't already there, it would be good to adopt these names as this is what they are usually known by.
I was wrong. Looked around and a bit and found out that these things already exist in Enumerable
and from enumerate.rb it looks like we would need to implement them.
@lokeshh For me, it seems like NMatrix should be fast & minimal in the first place, "fancy" things go to daru, probably.
So, as each_row
without block returns decent Enumerator
, you always can do matrix.each_row.reject
, or matrix.each_column.select
. Unfortunately, #550 is currently standing in the way of this usage. Another possible consideration is maybe you want matrix.map_rows
to produce NMatrix again, but probably calling .to_nm
on the result is probably good enough?..
Have you tried using #inject_rank
along with a select or reject?