Stream: helpdesk (published)

Topic: filter matrix by rows


view this post on Zulip Moorits Muru (May 03 2022 at 08:31):

I have a matrix d where the first three columns are coordinates followed by some other data. I want to make a coordinate cut, so in essence, filter by rows by some function f.

I hoped I could do filter(f, eachrow(d)), but it seems filter doesn't like generators. My current solution is to use mapslices to create a mask and use the mask on data. But, if possible, I would like to filter without making a mask.

view this post on Zulip Gunnar Farnebäck (May 03 2022 at 08:55):

Would a filtered comprehension work for you?

[r for r in eachrow(d) if f(r)]

view this post on Zulip Philipp Gabler (May 03 2022 at 13:23):

Which, IIRC, lowers to something involving Iterators.filter which works on generators.


Last updated: Oct 02 2023 at 04:34 UTC