# [Scipy-tickets] [SciPy] #805: Faster implementation of argsreduce in scipy.stats.distributions

SciPy scipy-tickets@scipy....
Mon Dec 1 05:54:24 CST 2008

```#805: Faster implementation of argsreduce in scipy.stats.distributions
-------------------------+--------------------------------------------------
Reporter:  pbrod        |       Owner:  somebody
Type:  enhancement  |      Status:  new
Priority:  normal       |   Milestone:  0.8
Component:  scipy.stats  |     Version:  devel
Severity:  normal       |    Keywords:
-------------------------+--------------------------------------------------
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]}}}

--
Ticket URL: <http://scipy.org/scipy/scipy/ticket/805>
SciPy <http://www.scipy.org/>
SciPy is open-source software for mathematics, science, and engineering.
```