Re: [Numpy-discussion] problem with view() and strided arrays?

2008-04-24 Thread Robert Kern
On Thu, Apr 24, 2008 at 10:53 PM, Charles R Harris <[EMAIL PROTECTED]> wrote: > Views only work for items of the same size. You are trying to view bytes as > two byte values. View is like strict pointer aliasing in C. No, it works just fine if you have a contiguous array. In [5]: from numpy impo

Re: [Numpy-discussion] problem with view() and strided arrays?

2008-04-24 Thread Charles R Harris
On Thu, Apr 24, 2008 at 10:00 AM, Zachary Pincus <[EMAIL PROTECTED]> wrote: > > It seems like 'view' won't create a view where the stride length is > > not a whole multiple of the dtype's itemsize. However, since strides > > are measured in bytes (right?), this shouldn't be a problem. > > > Actual

Re: [Numpy-discussion] Matrix Class [was numpy release]

2008-04-24 Thread Charles R Harris
On Thu, Apr 24, 2008 at 5:45 PM, Timothy Hochberg <[EMAIL PROTECTED]> wrote: > > > Chris.Barker wrote: > >> Alan G Isaac wrote: >> > the cost of complexity should be justified by a gain in functionality. >> >> I don't think functionality is the right word here. the Matrix class(es) >> is all about

Re: [Numpy-discussion] Matrix Class [was numpy release]

2008-04-24 Thread Bill Spotz
On Apr 24, 2008, at 5:45 PM, Timothy Hochberg wrote: Bill Spotz wrote: > I have generally thought about this in the context of, say, a > Krylov-space iterative method, and what that type of interface would > lead to the most readable code. Can you whip up a small example, starting with the curr

Re: [Numpy-discussion] "aligned" matrix / ctypes

2008-04-24 Thread David Cournapeau
On Fri, 2008-04-25 at 04:15 +0200, Sturla Molden wrote: > The problem with alignment on 3 byte boundaries, is that 3 is a prime and > not a factor of the size of any common data type. (The only exception I > can think of is 24 bit RGB values.) So in general, the elements in an > array for which the

Re: [Numpy-discussion] "aligned" matrix / ctypes

2008-04-24 Thread Sturla Molden
The problem with alignment on 3 byte boundaries, is that 3 is a prime and not a factor of the size of any common data type. (The only exception I can think of is 24 bit RGB values.) So in general, the elements in an array for which the first element is aligned on a 3 byte boundary, may or may not

Re: [Numpy-discussion] Fixing #736 and possible memory leak

2008-04-24 Thread Charles R Harris
On Thu, Apr 24, 2008 at 5:58 PM, Robert Kern <[EMAIL PROTECTED]> wrote: > On Thu, Apr 24, 2008 at 5:37 PM, Charles R Harris > <[EMAIL PROTECTED]> wrote: > > Hi, > > > > I've been looking into ticket #736 and playing with some things. In > > arrayobject.c starting at line 8534 I added a check for s

Re: [Numpy-discussion] Fixing #736 and possible memory leak

2008-04-24 Thread Charles R Harris
On Thu, Apr 24, 2008 at 7:11 PM, Charles R Harris <[EMAIL PROTECTED]> wrote: > > > On Thu, Apr 24, 2008 at 5:58 PM, Robert Kern <[EMAIL PROTECTED]> > wrote: > >> On Thu, Apr 24, 2008 at 5:37 PM, Charles R Harris >> <[EMAIL PROTECTED]> wrote: >> > Hi, >> > >> > I've been looking into ticket #736 an

Re: [Numpy-discussion] Generating Bell Curves (was: Using normal() )

2008-04-24 Thread Keith Goodman
On Thu, Apr 24, 2008 at 4:15 PM, Rich Shepard <[EMAIL PROTECTED]> wrote: >We need to generate bell-shaped curves given a midpoint, width (where y=0) A Gaussian never reaches zero. But I suppose your code will return a zero for large x when y is less than the smallest number your computer can h

Re: [Numpy-discussion] numpy release

2008-04-24 Thread Bill Baxter
On Fri, Apr 25, 2008 at 10:23 AM, Christopher Barker <[EMAIL PROTECTED]> wrote: > Alan G Isaac wrote: > > On Thu, 24 Apr 2008, Christopher Barker apparently wrote: > >> I suppose a "Vector" can be either a (n,1) or a (1,n) > >> matrix that allows single indexing. > > > > This bothers me. > >

Re: [Numpy-discussion] numpy release

2008-04-24 Thread Christopher Barker
Alan G Isaac wrote: > On Thu, 24 Apr 2008, Christopher Barker apparently wrote: >> I suppose a "Vector" can be either a (n,1) or a (1,n) >> matrix that allows single indexing. > > This bothers me. > > So, if X is 2 by 2, then X[0] will be a row vector. > But if X is 1 by 2, then X[0] will be a

Re: [Numpy-discussion] Fixing #736 and possible memory leak

2008-04-24 Thread Charles R Harris
On Thu, Apr 24, 2008 at 5:58 PM, Robert Kern <[EMAIL PROTECTED]> wrote: > On Thu, Apr 24, 2008 at 5:37 PM, Charles R Harris > <[EMAIL PROTECTED]> wrote: > > Hi, > > > > I've been looking into ticket #736 and playing with some things. In > > arrayobject.c starting at line 8534 I added a check for s

Re: [Numpy-discussion] numpy release

2008-04-24 Thread Bill Baxter
On Thu, Apr 24, 2008 at 11:16 AM, Timothy Hochberg <[EMAIL PROTECTED]> wrote: > > [CHOP] > > The proposals thus far don't address two of the major issues I have with the > matrix class: The thing that seems missing to me is support for LAPACK's banded and packed (triangular) storage formats. I do

Re: [Numpy-discussion] Fixing #736 and possible memory leak

2008-04-24 Thread Robert Kern
On Thu, Apr 24, 2008 at 5:37 PM, Charles R Harris <[EMAIL PROTECTED]> wrote: > Hi, > > I've been looking into ticket #736 and playing with some things. In > arrayobject.c starting at line 8534 I added a check for strings. > > if (PyString_Check(op)) { > r = Array_FromPyScalar(op

Re: [Numpy-discussion] Matrix Class [was numpy release]

2008-04-24 Thread Timothy Hochberg
Chris.Barker wrote: > Alan G Isaac wrote: > > the cost of complexity should be justified by a gain in functionality. > > I don't think functionality is the right word here. the Matrix class(es) > is all about clean, convenient API, i.e. style, not functionality -- we > have all the functionality a

Re: [Numpy-discussion] numpy release

2008-04-24 Thread Stéfan van der Walt
2008/4/25 Alan G Isaac <[EMAIL PROTECTED]>: > So, if X is 2 by 2, then X[0] will be a row vector. > But if X is 1 by 2, then X[0] will be a scalar? > Ouch! > Bye bye generic code. Yup. That's the current state of things. Stéfan ___ Numpy-discussion

[Numpy-discussion] Generating Bell Curves (was: Using normal() )

2008-04-24 Thread Rich Shepard
Thanks to several of you I produced test code using the normal density function, and it does not do what we need. Neither does the Gaussian function using fwhm that I've tried. The latter comes closer, but the ends do not reach y=0 when the inflection point is y=0.5. So, let me ask the colle

[Numpy-discussion] Fixing #736 and possible memory leak

2008-04-24 Thread Charles R Harris
Hi, I've been looking into ticket #736 and playing with some things. In arrayobject.c starting at line 8534 I added a check for strings. if (PyString_Check(op)) { r = Array_FromPyScalar(op, newtype); } if (PySequence_Check(op)) { PyObject *thiserr =

Re: [Numpy-discussion] numpy release

2008-04-24 Thread Alan G Isaac
On Thu, 24 Apr 2008, Christopher Barker apparently wrote: > I suppose a "Vector" can be either a (n,1) or a (1,n) > matrix that allows single indexing. This bothers me. So, if X is 2 by 2, then X[0] will be a row vector. But if X is 1 by 2, then X[0] will be a scalar? Ouch! Bye bye generic code

Re: [Numpy-discussion] ndarray.__mul__ is too gready?

2008-04-24 Thread Eike Welk
Just for the record, because I had a very similar problem: On Wednesday 23 January 2008 12:11, Pearu Peterson wrote: > Users may accidentally hit vector * matrix and this should raise > an exception. But when vector is numpy array, then ndarray.__mul__ > calls element * A for each array element an

Re: [Numpy-discussion] numpy release

2008-04-24 Thread Alan G Isaac
On Wed, 23 Apr 2008, Timothy Hochberg apparently wrote: > I think the way to go is to probably add some meta > information I have added this as Proposal 4 at http://www.scipy.org/MatrixIndexing> Forgive anything said the misrepresents your intent. Cheers, Alan

Re: [Numpy-discussion] "aligned" matrix / ctypes

2008-04-24 Thread Anne Archibald
On 24/04/2008, Zachary Pincus <[EMAIL PROTECTED]> wrote: > In the mean time, is there any way to (from within python) construct > an array from another array by specifying the dtype and strides? That > is, some other way to do the view/slice business directly? There's the ndarray constructor,

Re: [Numpy-discussion] "aligned" matrix / ctypes

2008-04-24 Thread Robert Kern
On Thu, Apr 24, 2008 at 4:57 PM, Zachary Pincus <[EMAIL PROTECTED]> wrote: > The reason that one must slice before .view()ing to allow arbitrary > alignment is as follows. Imagine that we want rows of four 2-byte > shorts aligned to 3-byte boundaries. (Assume that we already have a > buffer th

Re: [Numpy-discussion] "aligned" matrix / ctypes

2008-04-24 Thread Zachary Pincus
Zach: >> Here's my attempt at aligned_empty(). It only accepts alignments >> that are >> an integer multiple (or divisor) of the dtype's itemsize, because of >> limitations in ndarray.view(). Robert: > aligned_empty() works for me (after removing the if: suite that guards > this case) because it

Re: [Numpy-discussion] numpy release

2008-04-24 Thread Alan G Isaac
On Thu, 24 Apr 2008, Christopher Barker apparently wrote: > for r in MyMatrix.A: Of course: this possibility is mentioned explicitly in several of my posts. There are a few different answers to why asking users to do this annoying: 1. It is a deviation from the behavior of 2d arrays

Re: [Numpy-discussion] numpy release

2008-04-24 Thread Christopher Barker
Alan G Isaac wrote: > the > cost of complexity should be justified by a gain in > functionality. I don't think functionality is the right word here. the Matrix class(es) is all about clean, convenient API, i.e. style, not functionality -- we have all the functionality already, indeed we have i

[Numpy-discussion] EPD PIL _imaging C module

2008-04-24 Thread Lin Shao
Running scipy.test() in the latest EPD windows distribution, I got the following exception: == ERROR: test_imresize (scipy.misc.tests.test_pilutil.test_pilutil) -

Re: [Numpy-discussion] numpy release

2008-04-24 Thread Jarrod Millman
On Thu, Apr 24, 2008 at 1:22 PM, David Huard wrote: > Assuming we want the next version to : ignore values outside of range and > accept and return the bin edges instead of the left edges, here could be the > new signature for 1.1: > h, edges = histogram(a, bins=10, normed=False, range=None, norm

Re: [Numpy-discussion] Using normal()

2008-04-24 Thread Rich Shepard
On Thu, 24 Apr 2008, Robert Kern wrote: > No, it's not! scale is the standard deviation of the Normal distribution, > not half the FWHM! OK. Thanks for clearing up my mis-understanding. Rich -- Richard B. Shepard, Ph.D. | IntegrityCredibility Applied Ecosystem Ser

Re: [Numpy-discussion] Using normal()

2008-04-24 Thread Robert Kern
On Thu, Apr 24, 2008 at 1:39 PM, Rich Shepard <[EMAIL PROTECTED]> wrote: > On Thu, 24 Apr 2008, Joris De Ridder wrote: > > > Scale is half the width between the inflection points, mind the factor of > > 2. > > Joris, > >So, half of the full width at half the maximum height. Thank you. No, i

Re: [Numpy-discussion] Using normal()

2008-04-24 Thread Rich Shepard
On Thu, 24 Apr 2008, Zachary Pincus wrote: > I assume you 'from numpy import *'? This is why it works -- because that > import causes the python built-in exp() to be replaced (in the current > namespace) by numpy.exp(). The equivalent (I think): import numpy as nx. Rich -- Richard B. Shepar

Re: [Numpy-discussion] Using normal()

2008-04-24 Thread Anne Archibald
On 24/04/2008, Keith Goodman <[EMAIL PROTECTED]> wrote: > On Thu, Apr 24, 2008 at 10:01 AM, Rich Shepard <[EMAIL PROTECTED]> wrote: > >In the application's function I now have: > > > >from numpy import * > > > >x = nx.arange(0, 100, 0.1) > >y = nx.normal(center,width) # passe

Re: [Numpy-discussion] "aligned" matrix / ctypes

2008-04-24 Thread Robert Kern
On Thu, Apr 24, 2008 at 11:29 AM, Zachary Pincus <[EMAIL PROTECTED]> wrote: > Here's my attempt at aligned_empty(). It only accepts alignments that are > an integer multiple (or divisor) of the dtype's itemsize, because of > limitations in ndarray.view(). aligned_empty() works for me (after remov

Re: [Numpy-discussion] Using normal()

2008-04-24 Thread Rich Shepard
On Thu, 24 Apr 2008, Zachary Pincus wrote: > Python's built in pow() and exp() functions can't handle numpy arrays, and > thus try (and fail) to convert arrays to scalar values. You want to use > numpy.exp and numpy.power (or just the ** operator), to do these > operations to numpy arrays elementw

Re: [Numpy-discussion] Using normal()

2008-04-24 Thread Rich Shepard
On Thu, 24 Apr 2008, Joris De Ridder wrote: > Scale is half the width between the inflection points, mind the factor of > 2. Joris, So, half of the full width at half the maximum height. Thank you. Rich -- Richard B. Shepard, Ph.D. | IntegrityCredibility Applied

Re: [Numpy-discussion] numpy as a setuptools dependency

2008-04-24 Thread Robert Kern
On Thu, Apr 24, 2008 at 11:04 AM, Andreas Klöckner <[EMAIL PROTECTED]> wrote: > Hi all, > > numpy (1.0.4 anyway) doesn't seem to install right when it's pulled in as a > setuptools depdency from a package. If you need an example: > > http://pypi.python.org/pypi/PyUblas/0.92.3 > > This is the er

Re: [Numpy-discussion] numpy release

2008-04-24 Thread David Huard
The problem I see with C is that it will break compatibility with the other histogram functions, which also use bins. So here is suggestion E: The most common use case ( I think) is the following: h, b = histogram(r, number_of_bins, normed=True/False) for which the function behaves correctly. As

Re: [Numpy-discussion] Using normal()

2008-04-24 Thread Joris De Ridder
On 24 Apr 2008, at 19:26, Rich Shepard wrote: >> norm = 1 / (scale * sqrt(2 * pi)) >> y = norm * exp(-power((x - loc), 2) / (2 * scale**2)) > > Can do. So, scale would equate to width and loc to center, yes? Scale is half the width between the inflection points, mind the factor of 2. J. D

Re: [Numpy-discussion] Using normal()

2008-04-24 Thread Zachary Pincus
> It works for me: > >>> x = arange(0,10) >>> scale=1 >>> loc=1 >>> norm = 1 / (scale * sqrt(2 * pi)) >>> y = norm * exp(-power((x - loc), 2) / (2 * scale**2)) >>> y > > array([ 1.46762663e-01, 3.98942280e-01, 1.46762663e-01, > 5.39909665e-02, 2.68805194e-03, 1.33830226e-04, >

[Numpy-discussion] Fwd: Re: numpy as a setuptools dependency

2008-04-24 Thread Andreas Klöckner
Ok, forwarding this to distutils-sig. :) Andreas --- Begin Message --- Ooh. I am glad someone else is seeing this. I see the same thing when I try to install Twisted 8 pulled in as a setuptools dependency. My guess is that this is a setuptools problem, not a problem with numpy or Twisted. B

Re: [Numpy-discussion] Using normal()

2008-04-24 Thread Keith Goodman
On Thu, Apr 24, 2008 at 10:51 AM, Rich Shepard <[EMAIL PROTECTED]> wrote: > On Thu, 24 Apr 2008, Keith Goodman wrote: > > > norm = 1 / (scale * sqrt(2 * pi)) > > y = norm * exp(-power((x - loc), 2) / (2 * scale**2)) > >Hmm-m-m. I don't understand the source of the error: > >y = norm * exp

Re: [Numpy-discussion] Using normal()

2008-04-24 Thread Zachary Pincus
>> norm = 1 / (scale * sqrt(2 * pi)) >> y = norm * exp(-power((x - loc), 2) / (2 * scale**2)) > > Hmm-m-m. I don't understand the source of the error: > > y = norm * exp(-pow((x - loc), 2) / (2 * scale**2)) > TypeError: only length-1 arrays can be converted to Python scalars Python's built in

Re: [Numpy-discussion] Using normal()

2008-04-24 Thread Rich Shepard
On Thu, 24 Apr 2008, Keith Goodman wrote: > norm = 1 / (scale * sqrt(2 * pi)) > y = norm * exp(-power((x - loc), 2) / (2 * scale**2)) Hmm-m-m. I don't understand the source of the error: y = norm * exp(-pow((x - loc), 2) / (2 * scale**2)) TypeError: only length-1 arrays can be converted to

Re: [Numpy-discussion] Using normal()

2008-04-24 Thread Rich Shepard
On Thu, 24 Apr 2008, Zachary Pincus wrote: > The only remaining mystery is how 'loc' and 'scale' -- the parameters of > numpy.random.normal -- map to 'mean' and 'standard deviation', which is > how a normal distribution is usually parameterized. Fortunately, the > documentation reveals this: > > >

Re: [Numpy-discussion] numpy as a setuptools dependency

2008-04-24 Thread Brian Granger
Ooh. I am glad someone else is seeing this. I see the same thing when I try to install Twisted 8 pulled in as a setuptools dependency. My guess is that this is a setuptools problem, not a problem with numpy or Twisted. Brian On Thu, Apr 24, 2008 at 10:04 AM, Andreas Klöckner <[EMAIL PROTECT

Re: [Numpy-discussion] Using normal()

2008-04-24 Thread Zachary Pincus
> The syntax is normal(loc=0.0, scale=1.0, size=None), but I've not > seen > what those represent, nor how to properly invoke this function. A > clue will > be much appreciated. > > I want to call normal() passing at least the width of the curve(at > the end > points where y=0.0), and the

Re: [Numpy-discussion] Using normal()

2008-04-24 Thread Rich Shepard
On Thu, 24 Apr 2008, Keith Goodman wrote: > It's random.normal(loc, scale). But that will give you random x values > drawn from the normal distribution, not y values at your x. So you'll have > to code your own normal, which will probably look something like Keith, I overlooked that, thanks.

Re: [Numpy-discussion] Using normal()

2008-04-24 Thread Keith Goodman
On Thu, Apr 24, 2008 at 10:01 AM, Rich Shepard <[EMAIL PROTECTED]> wrote: >In the application's function I now have: > >from numpy import * > >x = nx.arange(0, 100, 0.1) >y = nx.normal(center,width) # passed to the function when called > > and I then pass x,y to PyX for plotting.

Re: [Numpy-discussion] numpy release

2008-04-24 Thread Travis E. Oliphant
Pauli Virtanen wrote: > > C) Create a new parameter with more sensible behavior and a name > different from "bins", and deprecate (at least giving sequences to) the > "bins" parameter: put up a DeprecationWarning if the user does this, but > still produce the same results as the old histogram.

[Numpy-discussion] Using normal()

2008-04-24 Thread Rich Shepard
Rereading "Guide to NumPy" once again, I saw what I had missed all the previous times: the normal() distribution function (Chapter 10, page 173). I have several questions on using it in my application. The syntax is normal(loc=0.0, scale=1.0, size=None), but I've not seen what those represen

Re: [Numpy-discussion] "aligned" matrix / ctypes

2008-04-24 Thread Zachary Pincus
Hi all, It's worth mentioning that there was some discussion of adding an allocator for aligned arrays. It got sidetracked into a discussion of SSE support for numpy, but there are all sorts of reasons to want aligned arrays in numpy, as this post demonstrates. Seeing as it's just a few lines wo

[Numpy-discussion] numpy as a setuptools dependency

2008-04-24 Thread Andreas Klöckner
Hi all, numpy (1.0.4 anyway) doesn't seem to install right when it's pulled in as a setuptools depdency from a package. If you need an example: http://pypi.python.org/pypi/PyUblas/0.92.3 This is the error message: error: /tmp/easy_install-BhSDYE/numpy-1.0.4/temp/tmpUk0utg/LLgCtQ: No such file

Re: [Numpy-discussion] problem with view() and strided arrays?

2008-04-24 Thread Zachary Pincus
> It seems like 'view' won't create a view where the stride length is > not a whole multiple of the dtype's itemsize. However, since strides > are measured in bytes (right?), this shouldn't be a problem. Actually -- it seems like view() doesn't work with strided arrays at all. (?) In : a = num

[Numpy-discussion] problem with view() and strided arrays?

2008-04-24 Thread Zachary Pincus
Hello all, I'm writing up a general function to allocate aligned numpy arrays (I'll post it shortly, as Anne suggested that such a function would be useful). However, I've run into trouble with using ndarray.view() in odd corner- cases: In : numpy.__version__ Out: '1.1.0.dev5077' In : a = n

Re: [Numpy-discussion] numpy release

2008-04-24 Thread Tommy Grav
I think a long term strategy needs to be adopted for histogram. Right now there is a great confusion in what the "bins" keyword does. Right now it is defined as the lower edge of each bin, meaning that the last bin is open ended and [inf,bin0> does not exist. While this may not be the right thing t

Re: [Numpy-discussion] numpy release

2008-04-24 Thread Pauli Virtanen
Wed, 23 Apr 2008 16:20:41 -0400, David Huard wrote: > 2008/4/23, Stéfan van der Walt <[EMAIL PROTECTED]>: > > Of those tickets, the following are serious: > > > > http://projects.scipy.org/scipy/numpy/ticket/605 (a patch is > > available?, David Huard) > > Fixing of histogram. > > I haven't found

Re: [Numpy-discussion] Unexpected behaviour by in place addition of array and masked array

2008-04-24 Thread Pierre GM
Hanno, On Thursday 24 April 2008 05:35:41 Hanno Klemm wrote: > >>> N.__version__ > '1.0.4' OK, you're using the "old" version of masked array. > I tried adding a masked array and a usual array in place and got back > the usual array. Is this expected behaviour? I would have expected to > get a m

Re: [Numpy-discussion] numpy release

2008-04-24 Thread Bruce Southey
Hi, I would like to use the matrix functionality but I, like others, get by without it. +1 to Tim's and Nadav's comments. As Tim said, there should be seamless integration between concepts of vectors and matrices - after all there really no distinction between them in linear algebra. -2 for ha

Re: [Numpy-discussion] numpy release

2008-04-24 Thread Nadav Horesh
Some, including me, stated that the matrix class suffer some deficiencies, so, after playing a bit with matrices, we always go back to the good old ndarray class. There were some arguments on this list what/if should be dome to correct it. I welcome any attempt to build a code that demonstrate

[Numpy-discussion] New web site for the F2PY. tool

2008-04-24 Thread Pearu Peterson
Hi, I have created a new web site for the F2PY tool: http://www.f2py.org that will be used to collect F2PY related information. At the moment, the site contains minimal information but hopefully this will improve in future. One can add content to the f2py.org site after registration (see Regi

Re: [Numpy-discussion] numpy release

2008-04-24 Thread Stéfan van der Walt
2008/4/24 Nadav Horesh <[EMAIL PROTECTED]>: > +1 +1 to what? I'm glad that Tim chimed in -- his opinion is always valued -- but I didn't see any concrete suggestions on how to improve the situation. I'll gladly wait for his code, though :) Regards Stéfan

Re: [Numpy-discussion] numpy release

2008-04-24 Thread Nadav Horesh
+1 Nadav -הודעה מקורית- מאת: [EMAIL PROTECTED] בשם Timothy Hochberg נשלח: ה 24-אפריל-08 04:16 אל: Discussion of Numerical Python נושא: Re: [Numpy-discussion] numpy release [CHOP] The proposals thus far don't address two of the major issues I have with the matrix class: 1. The ma

[Numpy-discussion] Unexpected behaviour by in place addition of array and masked array

2008-04-24 Thread Hanno Klemm
Hi, I tried adding a masked array and a usual array in place and got back the usual array. Is this expected behaviour? I would have expected to get a masked array back. The below example illustrates what I mean. >>> import numpy as N >>> a = N.zeros((3,3), dtype=float) >>> b = N.ma.MaskedArray