Re: [Numpy-discussion] Finding Unique Pixel Values

2010-07-22 Thread Ian Mallett
On Thu, Jul 22, 2010 at 10:05 PM, Charles R Harris < charlesr.har...@gmail.com> wrote: > Is that what you want, or do you just want to know how many unique indices > there are? As to encoding the RGB, unless there is a existing program your > best bet is probably to use a dot product, i.e., if pix

Re: [Numpy-discussion] Finding Unique Pixel Values

2010-07-22 Thread Charles R Harris
On Thu, Jul 22, 2010 at 9:59 PM, Ian Mallett wrote: > Hi again, > > I've condensed the problem down a lot, because I both presented it in an > overcomplicated way, and did not explain it particularly well. > > Condensed problem: > a = np.zeros(num_patches) > b = np.array(...) #created, and is siz

Re: [Numpy-discussion] Finding Unique Pixel Values

2010-07-22 Thread Ian Mallett
Hi again, I've condensed the problem down a lot, because I both presented it in an overcomplicated way, and did not explain it particularly well. Condensed problem: a = np.zeros(num_patches) b = np.array(...) #created, and is size 512^512 = 262,144 #Each value in "b" is an index into "a". #For ea

[Numpy-discussion] segmentation fault when installing with pip and python2.7

2010-07-22 Thread celil
Hello, I just installed numpy on Snow Leopard using pip. However, running the tests results in a segmentation fault. Has anybody else encountered this problem? How did you solve it? The sequence of commands that reproduce the bug is: $ pip install numpy $ python -c "import numpy; num

[Numpy-discussion] Finding Unique Pixel Values

2010-07-22 Thread Ian Mallett
Hi, So, I'm working on a radiosity renderer, and it's basically finished. I'm now trying to optimize it. Currently, by far the most computationally expensive operation is visibility testing, where pixels are counted by the type of patch that was drawn on them. Here's my current code, which I'm

Re: [Numpy-discussion] Crosstabulation

2010-07-22 Thread Friedrich Romstedt
2010/7/20 Vincent Schut : > slope_bin_edges = [0, 3, 15, 35] > landuse_bin_edges = [0, 1, 2, 3] > crosstab = numpy.histogram2d(landuse, slope, bins=(landuse_bin_edges, > slope_bin_edges)) I like it! I guess the actual bins are [0, 3), [3, 15) and [15, 35)? >From the docs, that is not so clear. E

Re: [Numpy-discussion] Custom ufuncs with Axis argument

2010-07-22 Thread John Salvatier
I should add that it is for ufuncs with number of arguments larger than 2. On Thu, Jul 22, 2010 at 2:47 PM, John Salvatier wrote: > What is the easiest way to give a custom ufunc an axis argument? I have > looked around the UFunc API, but I have not seen anything related to this. > __

[Numpy-discussion] Custom ufuncs with Axis argument

2010-07-22 Thread John Salvatier
What is the easiest way to give a custom ufunc an axis argument? I have looked around the UFunc API, but I have not seen anything related to this. ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-di

Re: [Numpy-discussion] list to array is slow

2010-07-22 Thread Skipper Seabold
On Thu, Jul 22, 2010 at 5:09 PM, marco cammarata wrote: > Hi, > > any idea why the simple code below is so slow ? > > import numpy as n > from time import time as t > > dims = (640,480) > m = n.random.random( dims ) > > l=[] > > for i in range(200): >        l.append(m) > > t0=t() > b=n.array(l) >

Re: [Numpy-discussion] subtract.reduce behavior

2010-07-22 Thread Johann Hibschman
Pauli Virtanen writes: > The documentation is incorrect. Thanks. The observed behavior is more like: if len(A) == 0: return op.identity else: r = A[0] for i in xrange(1, len(A): r = op(r, A[i]) return r -Johann ___ NumPy-D

Re: [Numpy-discussion] list to array is slow

2010-07-22 Thread Ian Mallett
On Thu, Jul 22, 2010 at 2:09 PM, marco cammarata wrote: > To convert the list into an array takes about 5 sec ... > Not too familiar with typical speeds, but at a guess, perhaps because it must convert 61.4 million (640*480*200) values? Just to *count* that high with xrange takes 1.6 seconds for

[Numpy-discussion] list to array is slow

2010-07-22 Thread marco cammarata
Hi, any idea why the simple code below is so slow ? import numpy as n from time import time as t dims = (640,480) m = n.random.random( dims ) l=[] for i in range(200): l.append(m) t0=t() b=n.array(l) print t()-t0 To convert the list into an array takes about 5 sec ... Thanks, marco

Re: [Numpy-discussion] subtract.reduce behavior

2010-07-22 Thread Pauli Virtanen
Thu, 22 Jul 2010 15:00:50 -0500, Johann Hibschman wrote: [clip] > Now, I'm on an older version (1.3.0), which might be the problem, but > which is "correct" here, the code or the docs? The documentation is incorrect. -- Pauli Virtanen ___ NumPy-Discus

Re: [Numpy-discussion] subtract.reduce behavior

2010-07-22 Thread Warren Weckesser
John Salvatier wrote: > I get the same result on 1.4.1 > > On Thu, Jul 22, 2010 at 1:00 PM, Johann Hibschman > mailto:jhibschman%2bnu...@gmail.com>> wrote: > > I'm trying to understand numpy.subtract.reduce. The documentation > doesn't seem to match the behavior. The documentation claims

Re: [Numpy-discussion] subtract.reduce behavior

2010-07-22 Thread John Salvatier
I get the same result on 1.4.1 On Thu, Jul 22, 2010 at 1:00 PM, Johann Hibschman < jhibschman+nu...@gmail.com > wrote: > I'm trying to understand numpy.subtract.reduce. The documentation > doesn't seem to match the behavior. The documentation claims > > For a one-dimensional array, reduce prod

[Numpy-discussion] subtract.reduce behavior

2010-07-22 Thread Johann Hibschman
I'm trying to understand numpy.subtract.reduce. The documentation doesn't seem to match the behavior. The documentation claims For a one-dimensional array, reduce produces results equivalent to: r = op.identity for i in xrange(len(A)): r = op(r,A[i]) return r However, numpy.subtra

Re: [Numpy-discussion] summarizing blocks of an array using a moving window

2010-07-22 Thread Keith Goodman
On Thu, Jul 22, 2010 at 10:35 AM, Warren Weckesser wrote: > Keith Goodman wrote: >> On Thu, Jul 22, 2010 at 7:48 AM, Warren Weckesser >> wrote: >> >> >>> Actually, because of the use of reshape(3,3,4), your second >>> example does make a copy. >>> >> >> When does reshape return a view and when do

Re: [Numpy-discussion] summarizing blocks of an array using a moving window

2010-07-22 Thread Warren Weckesser
Keith Goodman wrote: > On Thu, Jul 22, 2010 at 7:48 AM, Warren Weckesser > wrote: > > >> Actually, because of the use of reshape(3,3,4), your second >> example does make a copy. >> > > When does reshape return a view and when does it return a copy? > > According to the numpy.reshape do

Re: [Numpy-discussion] summarizing blocks of an array using a moving window

2010-07-22 Thread Robin Kraft
Vincent, Pauli, > From: Vincent Schut > - an other option would be some smart reshaping, which finally gives you > a [y//2, x//2, 2, 2] array, which you could then reduce to calculate > stats (mean, std, etc) on the last two axes. I *think* you'd have to > first reshape both x and y axes, a

Re: [Numpy-discussion] Can't get ufunc to work for integers

2010-07-22 Thread John Salvatier
This did end up solving my problem. Thanks! On Thu, Jul 22, 2010 at 9:25 AM, John Salvatier wrote: > Oh, ok. That makes sense. Thanks for the speedy help. > > John > > > On Thu, Jul 22, 2010 at 9:14 AM, Pauli Virtanen wrote: > >> Thu, 22 Jul 2010 08:49:09 -0700, John Salvatier wrote: >> > I am t

Re: [Numpy-discussion] Can't get ufunc to work for integers

2010-07-22 Thread John Salvatier
Oh, ok. That makes sense. Thanks for the speedy help. John On Thu, Jul 22, 2010 at 9:14 AM, Pauli Virtanen wrote: > Thu, 22 Jul 2010 08:49:09 -0700, John Salvatier wrote: > > I am trying to learn how to create ufuncs, and I got a ufunc to compile > > correctly with the signature int -> double,

Re: [Numpy-discussion] Can't get ufunc to work for integers

2010-07-22 Thread Pauli Virtanen
Thu, 22 Jul 2010 08:49:09 -0700, John Salvatier wrote: > I am trying to learn how to create ufuncs, and I got a ufunc to compile > correctly with the signature int -> double, but I can't get it to accept > any arguments. My function is testfunc and I used NPY_INT as the first > signature and NPY_DO

[Numpy-discussion] Can't get ufunc to work for integers

2010-07-22 Thread John Salvatier
Hello, I am trying to learn how to create ufuncs, and I got a ufunc to compile correctly with the signature int -> double, but I can't get it to accept any arguments. My function is testfunc and I used NPY_INT as the first signature and NPY_DOUBLE as the second signature. What should I look at to

Re: [Numpy-discussion] summarizing blocks of an array using a moving window

2010-07-22 Thread Keith Goodman
On Thu, Jul 22, 2010 at 7:48 AM, Warren Weckesser wrote: > Actually, because of the use of reshape(3,3,4), your second > example does make a copy. When does reshape return a view and when does it return a copy? Here's a simple example that returns a view: >> x = np.array([1,2,3,4]) >> y = x.re

Re: [Numpy-discussion] summarizing blocks of an array using a moving window

2010-07-22 Thread Warren Weckesser
Pauli Virtanen wrote: > Thu, 22 Jul 2010 00:47:20 -0400, Robin Kraft wrote: > [clip] > >> Let's say the image looks like this: np.random.randint(0,2, >> 16).reshape(4,4) >> >> array([[0, 0, 0, 1], >>[0, 0, 1, 1], >>[1, 1, 0, 0], >>[0, 0, 0, 0]]) >> >> I want to use a squa

Re: [Numpy-discussion] summarizing blocks of an array using a moving window

2010-07-22 Thread Pauli Virtanen
Thu, 22 Jul 2010 00:47:20 -0400, Robin Kraft wrote: [clip] > Let's say the image looks like this: np.random.randint(0,2, > 16).reshape(4,4) > > array([[0, 0, 0, 1], >[0, 0, 1, 1], >[1, 1, 0, 0], >[0, 0, 0, 0]]) > > I want to use a square, non-overlapping moving window for

Re: [Numpy-discussion] summarizing blocks of an array using a moving window

2010-07-22 Thread Vincent Schut
On 07/22/2010 06:47 AM, Robin Kraft wrote: > Hello all, > > The short version: For a given NxN array, is there an efficient way to use a > moving window to collect a summary statistic on a chunk of the array, and > insert it into another array? Hi Robin, been wrestling with similar stuff myself

[Numpy-discussion] irfft, odd size input and truncation

2010-07-22 Thread David Cournapeau
Hi, While looking at improving numpy.fft, I encountered some issue with the definition of irfft for odd-size input. The docstring says that irfft(x, n) when n < x.size truncate the high frequencies of x, but it seems this is ambiguous for odd-size x and even n ? In particular, I can't manage to em