You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The use is (partially) to select a non-zero entry at random and set it to zero, as part of a simulator. where and nonzero are pretty commonly used functions in numpy, it would be nice with a fast, built in function. Thanks anyhow
Yeah, I'd like to add something like where or nonzero to ndarray. I was curious about your use-case because where and nonzero didn't seem very useful without support for slicing with index arrays (which I'd also like to add to ndarray), but using them for random selection make sense.
I wonder if this problem would be more efficient if we had something like a bitmap. Storing indices just sounds so inefficient and an ndimensional bitmap could be a faster (just a wild idea?) way to represent a set of locations in an array.
I have also found that masks can often substitute for lists of indexes. But there are certainly use cases where this is not so. For example, I often have the need to get the values at a set of non-continuous indexes in a large matrix. If the matrix is large compared to the number of values you want to extract; e.g. you don't want to multiply a million zeroes to leave only 10 entries as-is. See e.g. the latter half of this file: https://github.com/tsoernes/rustdca/blob/master/src/gridfuncs.rs where any reference to neigh(bor) or ch(annel) is an array of indexes. Most of these algorithms cannot be feasibly be converted to the use of bitmasks. np.where is used all over in machine learning.
Activity
jturner314 commentedon Jun 24, 2018
This is an example that provides solutions for both problems:
It's probably not particularly fast, especially for arrays that don't have a row-major memory layout, but it works.
Out of curiosity, what's your use-case for this? There may be a better way to solve your problem than using a list of indices.
tsoernes commentedon Jun 24, 2018
The use is (partially) to select a non-zero entry at random and set it to zero, as part of a simulator.
whereandnonzeroare pretty commonly used functions in numpy, it would be nice with a fast, built in function. Thanks anyhowjturner314 commentedon Jun 24, 2018
Yeah, I'd like to add something like
whereornonzerotondarray. I was curious about your use-case becausewhereandnonzerodidn't seem very useful without support for slicing with index arrays (which I'd also like to add tondarray), but using them for random selection make sense.bluss commentedon Nov 22, 2018
I wonder if this problem would be more efficient if we had something like a bitmap. Storing indices just sounds so inefficient and an ndimensional bitmap could be a faster (just a wild idea?) way to represent a set of locations in an array.
tsoernes commentedon Nov 22, 2018
I have also found that masks can often substitute for lists of indexes. But there are certainly use cases where this is not so. For example, I often have the need to get the values at a set of non-continuous indexes in a large matrix. If the matrix is large compared to the number of values you want to extract; e.g. you don't want to multiply a million zeroes to leave only 10 entries as-is. See e.g. the latter half of this file: https://github.com/tsoernes/rustdca/blob/master/src/gridfuncs.rs where any reference to
neigh(bor)orch(annel)is an array of indexes. Most of these algorithms cannot be feasibly be converted to the use of bitmasks.np.whereis used all over in machine learning.bluss commentedon Nov 23, 2018
So, a sparse bitmask maybe?
tsoernes commentedon Nov 23, 2018
bluss commentedon Nov 24, 2018
I guess a good bitmask can handle both scenarios. There's an alternative to list of indices here https://github.com/brettwooldridge/SparseBitSet/blob/master/SparseBitSet.pdf and then there's roaring, and I'm not sure exactly what data structure it is using. https://github.com/RoaringBitmap/RoaringBitmap