Skipper Seabold | 1 Feb 05:39 2010
Picon

all() and any() with array-like input

I'm sure this has come up before, but it's difficult to search of any
and all...  This is tripping me up, but maybe there is just something
I am missing.

In [1]: import numpy as np

In [2]: X = [.2,.2,.2,.2,.2]

In [3]: np.all(X <= 1)
Out[3]: False

In [4]: np.all(X >= 0)
Out[4]: True

In [5]: np.all(np.asarray(X) <= 1)
Out[5]: True

In [6]: np.any(X>1)
Out[6]: True

I guess it's simple enough to use asarray, but I was just curious what
drives this behavior since the docs indicate that it should work with
array-like structures.

Skipper
Keith Goodman | 1 Feb 06:07 2010
Picon

Re: all() and any() with array-like input

On Sun, Jan 31, 2010 at 8:39 PM, Skipper Seabold <jsseabold <at> gmail.com> wrote:
> I'm sure this has come up before, but it's difficult to search of any
> and all...  This is tripping me up, but maybe there is just something
> I am missing.
>
> In [1]: import numpy as np
>
> In [2]: X = [.2,.2,.2,.2,.2]
>
> In [3]: np.all(X <= 1)
> Out[3]: False
>
> In [4]: np.all(X >= 0)
> Out[4]: True
>
> In [5]: np.all(np.asarray(X) <= 1)
> Out[5]: True
>
> In [6]: np.any(X>1)
> Out[6]: True
>
> I guess it's simple enough to use asarray, but I was just curious what
> drives this behavior since the docs indicate that it should work with
> array-like structures.

"X <= 1", where X is a list, is not array-like, it is a bool:

>>> X <= 1
False

(Continue reading)

Paul | 1 Feb 07:30 2010
Picon

circulant matrices

I would like to find,

argmin_c   norm( x - dot(phi, c), 2)

where x, c are vectors and phi is a circulant matrix. Is there a way
to do this with a built-in numpy or scipy function? LAPACK doesn't
seem to have a circulant matrix type. There is a Fortran library
NAPACK on netlib.org that has a circulant matrix type though I don't
know anything about it. I guess I could try to add these functions
with f2py.

I tried to solve this problem using a naive deconvolution approach
with fft's but it's not robust. I guess I have to do some more
research. I can't really afford to treat phi as anything other than
circulant (like a general banded or dense matrix) as it has to be
fast.

Any pointers would be appreciated.

Thanks,
Pål
Warren Weckesser | 1 Feb 08:53 2010

Re: circulant matrices

Paul wrote:
> I would like to find,
>
> argmin_c   norm( x - dot(phi, c), 2)
>
> where x, c are vectors and phi is a circulant matrix. Is there a way
> to do this with a built-in numpy or scipy function? LAPACK doesn't
> seem to have a circulant matrix type. There is a Fortran library
> NAPACK on netlib.org that has a circulant matrix type though I don't
> know anything about it. I guess I could try to add these functions
> with f2py.
>
> I tried to solve this problem using a naive deconvolution approach
> with fft's but it's not robust. I guess I have to do some more
> research. I can't really afford to treat phi as anything other than
> circulant (like a general banded or dense matrix) as it has to be
> fast.
>
>   

Is phi singular?  If not, then wouldn't you just solve dot(phi,c) = x for c?

Based on the wikipedia article 
http://en.wikipedia.org/wiki/Circulant_matrix,
I implemented a quick test of the FFT method--see the attached script.  
(Sorry,
my notation is the usual Ax=b instead of phi*c=x.)  It seems to work, and it
is much faster than linalg.solve(), but the script is the full extent of my
experience with circulant matrices (i.e. probably even more naive than
what you have already tried), so there are probably details that I am 
(Continue reading)

Paul | 1 Feb 23:48 2010
Picon

Re: circulant matrices

On Jan 31, 11:53 pm, Warren Weckesser <warren.weckes... <at> enthought.com>
wrote:
> Paul wrote:
> > I would like to find,
>
> > argmin_c   norm( x - dot(phi, c), 2)
>
> > where x, c are vectors and phi is a circulant matrix. Is there a way
> > to do this with a built-in numpy or scipy function? LAPACK doesn't
> > seem to have a circulant matrix type. There is a Fortran library
> > NAPACK on netlib.org that has a circulant matrix type though I don't
> > know anything about it. I guess I could try to add these functions
> > with f2py.
>
> > I tried to solve this problem using a naive deconvolution approach
> > with fft's but it's not robust. I guess I have to do some more
> > research. I can't really afford to treat phi as anything other than
> > circulant (like a general banded or dense matrix) as it has to be
> > fast.
>
> Is phi singular?  If not, then wouldn't you just solve dot(phi,c) = x for c?

Thank you for your example code! It helped me realize that I have been
doing something wrong.

phi is not singular and you are right that you can solve dot(phi,c) =
x directly, with the fast implementation that you provided. I am
guessing phi not being singular also means fc = fft(c) has no zeros.

My mistake is that my phi is not exactly circulant, that is, it has
(Continue reading)

josephsmidt@gmail.com | 2 Feb 03:19 2010
Picon

Theological Implications Of Mainstream Cosmological Ideas.


Third post.
_______________________________________________
SciPy-User mailing list
SciPy-User <at> scipy.org
http://mail.scipy.org/mailman/listinfo/scipy-user
Joseph Smidt | 2 Feb 03:43 2010
Picon

Re: Theological Implications Of Mainstream Cosmological Ideas.

Opps, wrong people.

On Mon, Feb 1, 2010 at 6:19 PM, josephsmidt <at> gmail.com
<josephsmidt <at> gmail.com> wrote:
>
> Third post.
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User <at> scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>
Alan G Isaac | 2 Feb 16:23 2010
Picon

sample from kernel density estimate

I have a kernel density estimate from scipy.stats.gaussian_kde.
What's the best way to sample from it?  (Not from the underlying data.)

Thanks,
Alan Isaac
josef.pktd | 2 Feb 16:31 2010
Picon

Re: sample from kernel density estimate

On Tue, Feb 2, 2010 at 10:23 AM, Alan G Isaac <aisaac <at> american.edu> wrote:
> I have a kernel density estimate from scipy.stats.gaussian_kde.
> What's the best way to sample from it?  (Not from the underlying data.)

I think stats.kde.gaussian_kde.resample  does it.
If I remember correctly, it samples from the underlying data and adds
a normal noise. I think I read somewhere that that is equivalent to
sampling from the kernel density directly.

Josef

>
> Thanks,
> Alan Isaac
> _______________________________________________
> SciPy-User mailing list
> SciPy-User <at> scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
josef.pktd | 2 Feb 16:52 2010
Picon

Re: sample from kernel density estimate

On Tue, Feb 2, 2010 at 10:31 AM,  <josef.pktd <at> gmail.com> wrote:
> On Tue, Feb 2, 2010 at 10:23 AM, Alan G Isaac <aisaac <at> american.edu> wrote:
>> I have a kernel density estimate from scipy.stats.gaussian_kde.
>> What's the best way to sample from it?  (Not from the underlying data.)
>
> I think stats.kde.gaussian_kde.resample  does it.
> If I remember correctly, it samples from the underlying data and adds
> a normal noise. I think I read somewhere that that is equivalent to
> sampling from the kernel density directly.

drawing a sample and running kstest will make a nice test case, it's
still missing in the test suite.
I will put it on my todo list.

Josef

>
> Josef
>
>
>>
>> Thanks,
>> Alan Isaac
>> _______________________________________________
>> SciPy-User mailing list
>> SciPy-User <at> scipy.org
>> http://mail.scipy.org/mailman/listinfo/scipy-user
>>
>

Gmane