[Numpy-discussion] Is there a pure numpy recipe for this?
Slaunger
Slaunger at gmail.com
Wed Mar 26 16:28:15 EDT 2014
jseabold wrote
> IIUC,
>
> [~/]
> [1]: np.logical_and([True, False, True], [False, False, True])
> [1]: array([False, False, True], dtype=bool)
>
> You can avoid looping over k since they're all the same length
>
> [~/]
> [3]: np.logical_and([[True, False],[False, True],[False, True]],
> [[False, False], [False, True], [True, True]])
> [3]:
> array([[False, False],
> [False, True],
> [False, True]], dtype=bool)
>
> [~/]
> [4]: np.sum(np.logical_and([[True, False],[False, True],[False,
> True]], [[False, False], [False, True], [True, True]]), axis=0)
> [4]: array([0, 2])
Well, yes, if you work with the pure f_k and g_k that is true, but this
two-dimensional array will have 4*10^14 elements and will exhaust my memory.
That is why I have found a more efficient method for finding only the much
fewer changes_at elements for each k, and these arrays have unequal length,
and has to be considered for eack k (which is tolerable as long as I avoid a
further inner loop for each k in explicit Python).
I could implement this in C and get it done sufficiently efficient. I just
like to make a point in demonstrating this is also doable in finite time in
Python/numpy.
--
View this message in context: http://numpy-discussion.10968.n7.nabble.com/Is-there-a-pure-numpy-recipe-for-this-tp37077p37081.html
Sent from the Numpy-discussion mailing list archive at Nabble.com.
More information about the NumPy-Discussion
mailing list