[Numpy-discussion] eigenface image too dark

2008-03-18 Thread royG
hi
while trying to make an eigenface image from a numpy array of floats i
tried this

from numpy import array
import Image

imagesize=(200,200)
def makeimage(inputarray,imagename):
  inputarray.shape=(-1,)
  newimg=Image.new('L', imagesize)
  newimg.putdata(inputarray)
  newimg.save(imagename)

since i am using images of 200X200 size,
i use an array with 4 elements  like
[ -92.35294118  -81.88235294  -67.58823529 ...,   -3.47058824
   -13.23529412   -9.76470588]
the problem is ,i get an image that is too dark.it looks like a face
but is too dark that even different arrays will create images that all
look alike!..
s there a way to 'tone it down' so that i can generate an eigenface
that can be displayed better?

thanks
RG
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] Proposed change to average function

2008-03-18 Thread David Huard
In the process of addressing tickets for the next release, Charles Harris
and I made some changes to the internals of the average function which also
affects which input are accepted as valid.

According to the current documentation, weights can either be 1D or any
shape that can be broadcasted to a's shape. It seems, though, that the
broadcasting was partially broken. After some thought, we are proposing that
average only accepts weights that are either
 - 1D with length equal to a's shape along axis.
 - the same shape as a.

and raises an error otherwise. I think this reduces the risk of unexpected
results but wanted to know if anyone disagrees with the change.

The proposed version is implemented in revision 4888.


Regards,

David Huard
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] numpy.ma bug: need sanity check in masked_where

2008-03-18 Thread Stéfan van der Walt
Hi Pierre

Thanks for your fix for #703.  Unfortunately, it seems to have broken
some tests:

http://buildbot.scipy.org/builders/Windows_XP_x86_MSVC/builds/276/steps/shell_2/logs/stdio

Regards
Stéfan

On Mon, Mar 17, 2008 at 7:26 PM, Eric Firing <[EMAIL PROTECTED]> wrote:
> Pierre,
>
>  I just tripped over what boils down to the sequence given below.  It
>  would be useful if the error in line 53 were trapped right away; as it
>  is, it results in a masked array that looks reasonable but fails in a
>  non-obvious way.
>
>  Eric
>
>  In [52]:x = [1,2]
>
>  In [53]:y = ma.masked_where(False, x)
>
>  In [54]:y
>  Out[54]:
>  masked_array(data = [1 2],
>mask = False,
>fill_value=99)
>
>
>  In [55]:y[1]
>  ---
>  IndexErrorTraceback (most recent call last)
>
>  /home/efiring/ in ()
>
>  /usr/local/lib/python2.5/site-packages/numpy/ma/core.pyc in
>  __getitem__(self, indx)
> 1307 if not getattr(dout,'ndim', False):
> 1308 # Just a scalar
>  -> 1309 if m is not nomask and m[indx]:
> 1310 return masked
> 1311 else:
>
>  IndexError: 0-d arrays can't be indexed
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] SVD error in Numpy. Bug?

2008-03-18 Thread Nils Wagner
On Tue, 18 Mar 2008 12:48:31 -0700 (PDT)
  Lou Pecora <[EMAIL PROTECTED]> wrote:
> I have run into a failure of complex SVD in numpy
> (version='1.0.3.1').  The error is:
> 
>  File
> "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/numpy/linalg/linalg.py",
> line 767, in svd
>raise LinAlgError, 'SVD did not converge'
> numpy.linalg.linalg.LinAlgError: SVD did not converge
> 
> The matrix is complex 36 x 36. Very slight changes in
> the matrix components (~ one part in 10^4) are enough
> to make the error go away.  I have never seen this
> before and it goes against the fact (I think it's a
> mathematical fact) that SVD always exists.  A
> hard-coded upper limit on the iteration number allowed
> somewhere in the SVD C code seems to be the problem.
> Read on.
> 
> A google search turned up a few messages, included
> this one from 2002 where the same error occurred
> infrequently, but randomly (it seemed):
> 
> --
> One online message in August 2002:
> 
> Ok, so after several hours of trying to read that
> code, I found
> the parameter that needs to be tuned.  In case anyone
> has this
> problem and finds this thread a year from now, here's
> your hint:
> 
>File: Src/dlapack_lite.c
> Subroutine: dlasd4_
> Line: 22562
> 
> There's a for loop there that limits the number of
> iterations to
> 20.  Increasing this value to 50 allows my matrix to
> converge.
> I have not bothered to test what the "best" value for
> this number
> is, though.  In any case, it appears the number just
> exists to
> prevent infinite loops, and 50 isn't really that much
> closer to
> infinity than 20  (Actually, I'm just going to set
> it to 100
> so I don't have to think about it ever again.)
> 
> Damian Menscher
> -- 
> -=#| Physics Grad Student & SysAdmin @ U Illinois
> Urbana-Champaign |#=-
> -=#| 488 LLP, 1110 W. Green St, Urbana, IL 61801
> Ofc:(217)333-0038 |#=-
> -=#| 1412 DCL, Workstation Services Group, CITES
> Ofc:(217)244-3862 |#=-
> -=#|  www.uiuc.edu/~menscher/
>Fax:(217)333-9819 |#=-
> --
> 
> I have looked in Src/dlapack_lite.c and line 22562 is
> no longer a line that sets a max. iterations
> parameter.  There are several set in the file, but
> that code is hard to figure (sort of a Fortran-in-C
> hybrid).  
> 
> Here's one, for example:
> 
>maxit = *n * 6 * *n;   // Line 887
> 
> I have no idea which parameter to tweak.  Apparently
> this error is still in numpy (at least to my version).
> Does anyone have a fix?  Should I start a ticket (I
> think this is what people do)?  Any help appreciated.
> 

Please can you post your matrix (in MatrixMarket format
io.mmwrite) to the list.

Cheers,

  Nils
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] SVD error in Numpy. Bug?

2008-03-18 Thread Matthieu Brucher
Hi,

I think it could happen, the search for an eignevalue is an iterative
process that can diverge sometimes. All SVD implementations have this hard
coded-limitation, so that the biorthogonalization can finish in finite time.
What is the determinant of your matrix ?

Matthieu

2008/3/18, Lou Pecora <[EMAIL PROTECTED]>:
>
> I have run into a failure of complex SVD in numpy
> (version='1.0.3.1').  The error is:
>
>   File
>
> "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/numpy/linalg/linalg.py",
> line 767, in svd
> raise LinAlgError, 'SVD did not converge'
> numpy.linalg.linalg.LinAlgError: SVD did not converge
>
> The matrix is complex 36 x 36. Very slight changes in
> the matrix components (~ one part in 10^4) are enough
> to make the error go away.  I have never seen this
> before and it goes against the fact (I think it's a
> mathematical fact) that SVD always exists.  A
> hard-coded upper limit on the iteration number allowed
> somewhere in the SVD C code seems to be the problem.
> Read on.
>
> A google search turned up a few messages, included
> this one from 2002 where the same error occurred
> infrequently, but randomly (it seemed):
>
> --
> One online message in August 2002:
>
> Ok, so after several hours of trying to read that
> code, I found
> the parameter that needs to be tuned.  In case anyone
> has this
> problem and finds this thread a year from now, here's
> your hint:
>
> File: Src/dlapack_lite.c
> Subroutine: dlasd4_
> Line: 22562
>
> There's a for loop there that limits the number of
> iterations to
> 20.  Increasing this value to 50 allows my matrix to
> converge.
> I have not bothered to test what the "best" value for
> this number
> is, though.  In any case, it appears the number just
> exists to
> prevent infinite loops, and 50 isn't really that much
> closer to
> infinity than 20  (Actually, I'm just going to set
> it to 100
> so I don't have to think about it ever again.)
>
> Damian Menscher
> --
> -=#| Physics Grad Student & SysAdmin @ U Illinois
> Urbana-Champaign |#=-
> -=#| 488 LLP, 1110 W. Green St, Urbana, IL 61801
> Ofc:(217)333-0038 |#=-
> -=#| 1412 DCL, Workstation Services Group, CITES
> Ofc:(217)244-3862 |#=-
> -=#|  www.uiuc.edu/~menscher/
> Fax:(217)333-9819 |#=-
> --
>
> I have looked in Src/dlapack_lite.c and line 22562 is
> no longer a line that sets a max. iterations
> parameter.  There are several set in the file, but
> that code is hard to figure (sort of a Fortran-in-C
> hybrid).
>
> Here's one, for example:
>
> maxit = *n * 6 * *n;   // Line 887
>
> I have no idea which parameter to tweak.  Apparently
> this error is still in numpy (at least to my version).
> Does anyone have a fix?  Should I start a ticket (I
> think this is what people do)?  Any help appreciated.
>
> I'm using a Mac Book Pro (Intel chip), system 10.4.11,
> Python 2.4.4.
>
>
>
>
> -- Lou Pecora,   my views are my own.
>
>
>
>   
> 
> Be a better friend, newshound, and
> know-it-all with Yahoo! Mobile.  Try it now.
> http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
>
> ___
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>



-- 
French PhD student
Website : http://matthieu-brucher.developpez.com/
Blogs : http://matt.eifelle.com and http://blog.developpez.com/?blog=92
LinkedIn : http://www.linkedin.com/in/matthieubrucher
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] SVD error in Numpy. Bug?

2008-03-18 Thread Lou Pecora
I have run into a failure of complex SVD in numpy
(version='1.0.3.1').  The error is:

  File
"/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/numpy/linalg/linalg.py",
line 767, in svd
raise LinAlgError, 'SVD did not converge'
numpy.linalg.linalg.LinAlgError: SVD did not converge

The matrix is complex 36 x 36. Very slight changes in
the matrix components (~ one part in 10^4) are enough
to make the error go away.  I have never seen this
before and it goes against the fact (I think it's a
mathematical fact) that SVD always exists.  A
hard-coded upper limit on the iteration number allowed
somewhere in the SVD C code seems to be the problem.
Read on.

A google search turned up a few messages, included
this one from 2002 where the same error occurred
infrequently, but randomly (it seemed):

--
One online message in August 2002:

Ok, so after several hours of trying to read that
code, I found
the parameter that needs to be tuned.  In case anyone
has this
problem and finds this thread a year from now, here's
your hint:

File: Src/dlapack_lite.c
Subroutine: dlasd4_
Line: 22562

There's a for loop there that limits the number of
iterations to
20.  Increasing this value to 50 allows my matrix to
converge.
I have not bothered to test what the "best" value for
this number
is, though.  In any case, it appears the number just
exists to
prevent infinite loops, and 50 isn't really that much
closer to
infinity than 20  (Actually, I'm just going to set
it to 100
so I don't have to think about it ever again.)

Damian Menscher
-- 
-=#| Physics Grad Student & SysAdmin @ U Illinois
Urbana-Champaign |#=-
-=#| 488 LLP, 1110 W. Green St, Urbana, IL 61801
Ofc:(217)333-0038 |#=-
-=#| 1412 DCL, Workstation Services Group, CITES
Ofc:(217)244-3862 |#=-
-=#|  www.uiuc.edu/~menscher/
Fax:(217)333-9819 |#=-
--

I have looked in Src/dlapack_lite.c and line 22562 is
no longer a line that sets a max. iterations
parameter.  There are several set in the file, but
that code is hard to figure (sort of a Fortran-in-C
hybrid).  

Here's one, for example:

maxit = *n * 6 * *n;   // Line 887

I have no idea which parameter to tweak.  Apparently
this error is still in numpy (at least to my version).
Does anyone have a fix?  Should I start a ticket (I
think this is what people do)?  Any help appreciated.

I'm using a Mac Book Pro (Intel chip), system 10.4.11,
Python 2.4.4.




-- Lou Pecora,   my views are my own.


  

Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ 

___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Record Arrays and ctypes Interfacing

2008-03-18 Thread vel . accel
On Tue, Mar 18, 2008 at 2:18 PM, Robert Kern <[EMAIL PROTECTED]> wrote:
>
> On Tue, Mar 18, 2008 at 9:48 AM,  <[EMAIL PROTECTED]> wrote:
>  > Hi all,
>  >
>  >  How do I handle numpy record arrays (heterogenous dtype) with ctypes?
>  >  The python side is reasonably obvious to me, but I'm confused about
>  >  how to declare my C function's signature; whether I need to include
>  >  the numpy array interface header file or not... etc...
>  >
>  >  It's not obvious to me how a heterogeneous dtype is handled on the C
>  >  side. Could someone give me a quick and dirty example.
>
>  Record arrays (loosely) correspond to arrays of C structs. The
>  correspondence is only loose because the C standard does not specify
>  how the struct members should be aligned. Different systems may place
>  padding in places where numpy didn't. There are often #pragmas one can
>  use to force a particular kind of padding. Here is a reasonably good
>  article on the subject:
>
>   http://en.wikipedia.org/wiki/Data_structure_alignment
>
>  You shouldn't need any numpy headers.
>
>  --
>  Robert Kern
>
>  "I have come to believe that the whole world is an enigma, a harmless
>  enigma that is made terrible by our own mad attempt to interpret it as
>  though it had an underlying truth."
>   -- Umberto Eco
>  ___
>  Numpy-discussion mailing list
>  Numpy-discussion@scipy.org
>  http://projects.scipy.org/mailman/listinfo/numpy-discussion
>

Thank you Robert.

I had figured out that all that was required was a struct analogous to
the dtype be defined in the C file. I inserted an simple example in
the ctypes entry of the Wiki for others' reference .
http://www.scipy.org/Cookbook/Ctypes#head-9c2123bb99fa424ed4a3fc0b4ef38cddf3aa21c6";>heterogeneous
types example
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Record Arrays and ctypes Interfacing

2008-03-18 Thread Robert Kern
On Tue, Mar 18, 2008 at 9:48 AM,  <[EMAIL PROTECTED]> wrote:
> Hi all,
>
>  How do I handle numpy record arrays (heterogenous dtype) with ctypes?
>  The python side is reasonably obvious to me, but I'm confused about
>  how to declare my C function's signature; whether I need to include
>  the numpy array interface header file or not... etc...
>
>  It's not obvious to me how a heterogeneous dtype is handled on the C
>  side. Could someone give me a quick and dirty example.

Record arrays (loosely) correspond to arrays of C structs. The
correspondence is only loose because the C standard does not specify
how the struct members should be aligned. Different systems may place
padding in places where numpy didn't. There are often #pragmas one can
use to force a particular kind of padding. Here is a reasonably good
article on the subject:

  http://en.wikipedia.org/wiki/Data_structure_alignment

You shouldn't need any numpy headers.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
 -- Umberto Eco
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] how to build a series of arrays as I go?

2008-03-18 Thread Robert Kern
On Tue, Mar 18, 2008 at 4:25 AM, Chris Withers <[EMAIL PROTECTED]> wrote:
> Robert Kern wrote:
>  > Appending to a list is almost always better than growing an array by
>  > concatenation. If you have a real need for speed, though, there are a
>  > few tricks you can do at the expense of complexity.
>
>  I don't for this project but I might in future, where can I read about this?

There was a thread on one of the scipy lists several years ago, I
think. Before April 2005 certainly because I found a message from
myself referencing it.

Basically, if you are constructing a 1D array by appending individual
elements, the stdlib's array module is actually quite useful. It uses
the same preallocation strategy as lists. You then use
numpy.fromstring(buffer(pyarray), dtype=whatever) to create the numpy
array.

If you are building up a 1D array by chunks instead of individual
elements, it probably depends on the type of the chunks. If the chunks
are already arrays, I believe that appending the chunks to a list and
using hstack() will be the best. If the chunks are still lists,
probably .extend()ing the accumulator list is probably best.

For (N>1)D arrays, append to lists.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
 -- Umberto Eco
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] how to build a series of arrays as I go?

2008-03-18 Thread Chris Withers
Alexander Michael wrote:
> Be default (if I understand correctly) the passing a regular array to
> MaskedArray will not copy it, so it less redundant than it may at
> first appear. The MaskedArray provides as masked *view* of the
> underlying array data you give it.

Cool, that was exactly what I wanted to hear :-)

cheers,

Chris

-- 
Simplistix - Content Management, Zope & Python Consulting
- http://www.simplistix.co.uk
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] newbie question - summing a list of arrays

2008-03-18 Thread Chris Withers
Alan G Isaac wrote:
> Again:
> http://www.scipy.org/Numpy_Example_List_With_Doc
> 
> Really, as a new NumPy user you should just keep
> this page open in your browser.

Point well made, it's a shame that summary doesn't form part of the book...

> Also, help(N.sum), of course.

Ah cool. I think I got put off as this doesn't often return much with 
matplotlib and I assumed numpy would be the same, my bad...

Chris

-- 
Simplistix - Content Management, Zope & Python Consulting
- http://www.simplistix.co.uk
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] newbie question - summing a list of arrays

2008-03-18 Thread Alan G Isaac
On Tue, 18 Mar 2008, Chris Withers apparently wrote:
> Where are the docs for sum? 

Again:
http://www.scipy.org/Numpy_Example_List_With_Doc

Really, as a new NumPy user you should just keep
this page open in your browser.

Also, help(N.sum), of course.

Cheers,
Alan Isaac



___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] newbie question - summing a list of arrays

2008-03-18 Thread Chris Withers
Manuel Metz wrote:
> Hm, in this case you can do it like this:
> 
> numpy.sum(numpy.array([numpy.sum(v) for k,v in data.items()]))

maybe:

numpy.num(data.values(),axis=0)

...would also work?

I can't actually use that though as the reason I need to do this is part 
of building stacked bar charts in matplotlib.

Chris

-- 
Simplistix - Content Management, Zope & Python Consulting
- http://www.simplistix.co.uk
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] newbie question - summing a list of arrays

2008-03-18 Thread Manuel Metz
Chris Withers wrote:
> Alan G Isaac wrote:
>> On Tue, 18 Mar 2008, Chris Withers apparently wrote:
>>> Say I have an aribtary number of arrays:
>>> arrays = [array([1,2,3]),array([4,5,6]),array([7,8,9])] 
>>> How can I sum these all together? 
>> Try N.sum(arrays,axis=0).
> 
> I assume N here is:
> 
> import numpy as N?
> 
> Yep, it is... and that works exactly as I expect.
> 
> Where are the docs for sum? Having had the book turn up as a massive PDF 
> with a poor index/toc, I'm finding it just as difficult to navigate as 
> the online docs :-(
> (I, like most people on this list I'd guess, sadly don't have the time 
> to sit and read the whole book cover-to-cover to extract the 10-20% I 
> need to know :-S)
> 
>> But must they be in a list?
>> An array of arrays (i.e., 2d array) is easy to sum.
> 
> Actually, I'm using a dict of arrays:
> 
> data = {
>   'series1':array([1,2,3]),
>   'series2':array([1,4,6]),
>'date':array([datetime(...),datetime(...),datetime(...)]),
>   }
> 
> If that gives the idea?

Hm, in this case you can do it like this:

numpy.sum(numpy.array([numpy.sum(v) for k,v in data.items()]))

> Is there perhaps a better way to store these series?
> (I'm a numpy newbie, I've skimmed the tutorial and it doesn't appear to 
> help here)
> 
> cheers,
> 
> Chris
> 
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] new question - summing a list of arrays

2008-03-18 Thread Manuel Metz
Manuel Metz wrote:
> Chris Withers wrote:
>> Hi All,
>>
>> Say I have an aribtary number of arrays:
>>
>> arrays = [array([1,2,3]),array([4,5,6]),array([7,8,9])]
>>
>> How can I sum these all together?
>>
>> My only solution so far is this:
>>
>> sum = arrays[0]
>> for a in arrays[1:]:
>>sum += a
>>
>> ...which is ugly :-S
>>
>> cheers,
>>
>> Chris
> 
> sum = sum(array(sum(a) for a in arrays]))

Ah, sorry, typo

sum = numpy.sum(numpy.array([numpy.sum(a) for a in arrays]))

and numpy.sum for clarity ...
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] new question - summing a list of arrays

2008-03-18 Thread lorenzo bolla
use the "axis" argument in sum.
L.

On Tue, Mar 18, 2008 at 4:27 PM, Chris Withers <[EMAIL PROTECTED]>
wrote:

> Keith Goodman wrote:
> >>> sum(x)
> >
> > matrix([[ 1.15063313],
> > [ 0.8841396 ],
> > [ 1.7370669 ]])
>
> When these are arrays, I just get a single number sum back...
>
> Chris
>
> --
> Simplistix - Content Management, Zope & Python Consulting
>- http://www.simplistix.co.uk
> ___
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>



-- 
Lorenzo Bolla
[EMAIL PROTECTED]
http://lorenzobolla.emurse.com/
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] new question - summing a list of arrays

2008-03-18 Thread Manuel Metz
Chris Withers wrote:
> Hi All,
> 
> Say I have an aribtary number of arrays:
> 
> arrays = [array([1,2,3]),array([4,5,6]),array([7,8,9])]
> 
> How can I sum these all together?
> 
> My only solution so far is this:
> 
> sum = arrays[0]
> for a in arrays[1:]:
>sum += a
> 
> ...which is ugly :-S
> 
> cheers,
> 
> Chris

sum = sum(array(sum(a) for a in arrays]))

Works also if arrays in list have different length ...

Manuel
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] newbie question - summing a list of arrays

2008-03-18 Thread Chris Withers
Alan G Isaac wrote:
> On Tue, 18 Mar 2008, Chris Withers apparently wrote:
>> Say I have an aribtary number of arrays:
>> arrays = [array([1,2,3]),array([4,5,6]),array([7,8,9])] 
>> How can I sum these all together? 
> 
> Try N.sum(arrays,axis=0).

I assume N here is:

import numpy as N?

Yep, it is... and that works exactly as I expect.

Where are the docs for sum? Having had the book turn up as a massive PDF 
with a poor index/toc, I'm finding it just as difficult to navigate as 
the online docs :-(
(I, like most people on this list I'd guess, sadly don't have the time 
to sit and read the whole book cover-to-cover to extract the 10-20% I 
need to know :-S)

> But must they be in a list?
> An array of arrays (i.e., 2d array) is easy to sum.

Actually, I'm using a dict of arrays:

data = {
  'series1':array([1,2,3]),
  'series2':array([1,4,6]),
   'date':array([datetime(...),datetime(...),datetime(...)]),
  }

If that gives the idea?

Is there perhaps a better way to store these series?
(I'm a numpy newbie, I've skimmed the tutorial and it doesn't appear to 
help here)

cheers,

Chris

-- 
Simplistix - Content Management, Zope & Python Consulting
- http://www.simplistix.co.uk
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] new question - summing a list of arrays

2008-03-18 Thread Chris Withers
Keith Goodman wrote:
>>> sum(x)
> 
> matrix([[ 1.15063313],
> [ 0.8841396 ],
> [ 1.7370669 ]])

When these are arrays, I just get a single number sum back...

Chris

-- 
Simplistix - Content Management, Zope & Python Consulting
- http://www.simplistix.co.uk
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] new question - summing a list of arrays

2008-03-18 Thread Charles R Harris
On Tue, Mar 18, 2008 at 9:12 AM, Chris Withers <[EMAIL PROTECTED]>
wrote:

> Hi All,
>
> Say I have an aribtary number of arrays:
>
> arrays = [array([1,2,3]),array([4,5,6]),array([7,8,9])]
>
> How can I sum these all together?
>
> My only solution so far is this:
>
> sum = arrays[0]
> for a in arrays[1:]:
>   sum += a
>
> ...which is ugly :-S
>

Doesn't look too bad to me. Alternatively, you could stack them together in
one big array and sum on the first axis, which might look cooler but isn't
likely to be any faster.

Chuck
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] new question - summing a list of arrays

2008-03-18 Thread Keith Goodman
On Tue, Mar 18, 2008 at 8:12 AM, Chris Withers <[EMAIL PROTECTED]> wrote:
> Hi All,
>
>  Say I have an aribtary number of arrays:
>
>  arrays = [array([1,2,3]),array([4,5,6]),array([7,8,9])]
>
>  How can I sum these all together?
>
>  My only solution so far is this:
>
>  sum = arrays[0]
>  for a in arrays[1:]:
>sum += a
>
>  ...which is ugly :-S

>> import numpy.matlib as M
>> x=[M.rand(3,1), M.rand(3,1), M.rand(3,1)]
>> x

[matrix([[ 0.77886042],
[ 0.51142657],
[ 0.68692362]]),
 matrix([[ 0.01367274],
[ 0.24491876],
[ 0.74441998]]),
 matrix([[ 0.35809997],
[ 0.12779427],
[ 0.3057233 ]])]
>> sum(x)

matrix([[ 1.15063313],
[ 0.8841396 ],
[ 1.7370669 ]])
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] new question - summing a list of arrays

2008-03-18 Thread Alan G Isaac
On Tue, 18 Mar 2008, Chris Withers apparently wrote:
> Say I have an aribtary number of arrays:
> arrays = [array([1,2,3]),array([4,5,6]),array([7,8,9])] 
> How can I sum these all together? 

Try N.sum(arrays,axis=0).

But must they be in a list?
An array of arrays (i.e., 2d array) is easy to sum.

> My only solution so far is this:
> sum = arrays[0] 
> for a in arrays[1:]:
>sum += a
> ...which is ugly :-S 

And changes the first array!

Cheers,
Alan Isaac



___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] new question - summing a list of arrays

2008-03-18 Thread Chris Withers
Hi All,

Say I have an aribtary number of arrays:

arrays = [array([1,2,3]),array([4,5,6]),array([7,8,9])]

How can I sum these all together?

My only solution so far is this:

sum = arrays[0]
for a in arrays[1:]:
   sum += a

...which is ugly :-S

cheers,

Chris


-- 
Simplistix - Content Management, Zope & Python Consulting
- http://www.simplistix.co.uk
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] Record Arrays and ctypes Interfacing

2008-03-18 Thread vel . accel
Hi all,

How do I handle numpy record arrays (heterogenous dtype) with ctypes?
The python side is reasonably obvious to me, but I'm confused about
how to declare my C function's signature; whether I need to include
the numpy array interface header file or not... etc...

It's not obvious to me how a heterogeneous dtype is handled on the C
side. Could someone give me a quick and dirty example.

Thank you,
-dieter
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] how to build a series of arrays as I go?

2008-03-18 Thread Alexander Michael
On Tue, Mar 18, 2008 at 5:27 AM, Chris Withers <[EMAIL PROTECTED]> wrote:
> Travis E. Oliphant wrote:
>  > Generally, arrays are not efficiently re-sized.  It is best to
>  > pre-allocate, or simply create a list by appending and then convert to
>  > an array after the fact as you have done.
>
>  True, although that feels like iterating over the data twice for no
>  reason, which feels a bit weird.
>
>  In my case, I want to create a masked array, it would be nice to be able
>  to do that straight from a list, rather than having to turn the list
>  into an array and then turning the array into a masked array.
>
>  If I'm off base on this, let me know :-)
>
>  cheers,
>
>  Chris

Be default (if I understand correctly) the passing a regular array to
MaskedArray will not copy it, so it less redundant than it may at
first appear. The MaskedArray provides as masked *view* of the
underlying array data you give it.
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] View ND Homogeneous Record Array as (N+1)D Array?

2008-03-18 Thread Alexander Michael
On Mon, Mar 17, 2008 at 4:55 PM, Robert Kern <[EMAIL PROTECTED]> wrote:
> On Mon, Mar 17, 2008 at 3:44 PM, Alexander Michael <[EMAIL PROTECTED]> wrote:
>  > Is there a way to view an N-dimensional array with a *homogeneous*
>  >  record dtype as an array of N+1 dimensions? An example will make it
>  >  clear:
>  >
>  >  import numpy
>  >  a = numpy.array([(1.0,2.0), (3.0,4.0)], dtype=[('A',float),('B',float)])
>  >  b = a.view(...) # do something magical
>  >  print b
>  >  array([[ 1.,  2.],
>  >[ 3.,  4.]])
>  >  b[0,0] = 0.0
>  >  print a
>  >  [(0.0, 2.0) (3.0, 4.0)]
>
>
>  Just use a.view(float) and then reshape as appropriate.
>
>  In [1]: import numpy
>
>  In [2]: a = numpy.array([(1.0,2.0), (3.0,4.0)], 
> dtype=[('A',float),('B',float)])
>
>  In [3]: a.view(float)
>  Out[3]: array([ 1.,  2.,  3.,  4.])
>
>  In [4]: b = _
>
>  In [5]: b.shape = a.shape + (-1,)
>
>  In [6]: b
>  Out[6]:
>
> array([[ 1.,  2.],
>[ 3.,  4.]])
>
>  In [7]: b[0,0] = 0.0
>
>  In [8]: a
>  Out[8]:
>  array([(0.0, 2.0), (3.0, 4.0)],
>   dtype=[('A', '>> a = numpy.array(
... [(1.0,2.0), (3.0,4.0), (5.0,6.0)],
... dtype=[('A',float),('B',float)])
>>> u = unpacked_view(a)
>>> u
array([[ 1.,  2.],
   [ 3.,  4.],
   [ 5.,  6.]])
>>> u.shape
(3, 2)

"""
if x.dtype.names:
ftypes = set([t for n,t in x.dtype.descr])
assert(len(ftypes) == 1)
ftype = ftypes.pop()
y = x.view(ftype)
unpacked_shape = x.shape + (-1,)
y.shape = unpacked_shape
return y
else:
return x
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] BUG with numpy.float64.tolist() ?

2008-03-18 Thread LB
I have two questions about numpy.float64 :
- why do numpy.float64 have a tolist method, whereas standard
python float hasn't ?
- why does it not return list ?

This seems to be the source of some bugs ( like this one, with
scipy.interpolate.spalde : 
http://groups.google.com/group/scipy-user/browse_thread/thread/47fefa8e519c85f6?hl=fr).

Did I miss something or should I add an entry to the bugtracker ?


--
LB
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] how to build a series of arrays as I go?

2008-03-18 Thread Chris Withers
Travis E. Oliphant wrote:
> Generally, arrays are not efficiently re-sized.  It is best to 
> pre-allocate, or simply create a list by appending and then convert to 
> an array after the fact as you have done.

True, although that feels like iterating over the data twice for no 
reason, which feels a bit weird.

In my case, I want to create a masked array, it would be nice to be able 
to do that straight from a list, rather than having to turn the list 
into an array and then turning the array into a masked array.

If I'm off base on this, let me know :-)

cheers,

Chris

-- 
Simplistix - Content Management, Zope & Python Consulting
- http://www.simplistix.co.uk
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] how to build a series of arrays as I go?

2008-03-18 Thread Chris Withers
Robert Kern wrote:
> Appending to a list is almost always better than growing an array by
> concatenation. If you have a real need for speed, though, there are a
> few tricks you can do at the expense of complexity.

I don't for this project but I might in future, where can I read about this?

cheers,

Chris

-- 
Simplistix - Content Management, Zope & Python Consulting
- http://www.simplistix.co.uk
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion