Ticket #805 (closed enhancement: fixed)
Faster implementation of argsreduce in scipy.stats.distributions
| Reported by: | pbrod | Owned by: | somebody |
|---|---|---|---|
| Priority: | normal | Milestone: | 0.8.0 |
| Component: | scipy.stats | Version: | devel |
| Keywords: | Cc: |
Description
The implementation of argsreduce below is about 10% faster than the original implementation in scipy.stats.distributions.py
def argsreduce(cond, *args):
""" Return the sequence of ravel(args[i]) where ravel(condition) is True in
1D
Example
>>> import numpy as np
>>> rand = np.random.random_sample
>>> A = rand((4,5))
>>> B = 2
>>> C = rand((1,5))
>>> cond = np.ones(A.shape)
>>> [A1,B1,C1] = argsreduce(cond,A,B,C)
>>> B1.shape
(20,)
>>> cond[2,:] = 0
>>> [A2,B2,C2] = argsreduce(cond,A,B,C)
>>> B2.shape
(15,)
"""
newargs = atleast_1d(*args)
if not isinstance(newargs,list):
newargs = [newargs,]
expand_arr = (cond==cond)
return [extract(cond,arr1*expand_arr) for arr1 in newargs]}}}
Attachments
Change History
Note: See
TracTickets for help on using
tickets.
