[Numpy-discussion] PSF GSoC 2010 (Py3K focus)

2010-03-08 Thread Jarrod Millman
Hello,

Given the interest in participating in the GSoC this summer, I am
forwarding a very interesting email from Titus Brown.  If you are
interested in doing a GSoC or mentoring, please read his email
carefully.

Basically, the PSF will be focuing on Py3K-related projects.  Given
Pauli's work on Py3K support for NumPy, I think we might be in a good
position to move forward on porting the rest of our stack to Py3K.  So
we should focus on projects to:

1. finish porting and testing NumPy with Py3K
2. port and test SciPy with Py3K
3. port and test matplotlib with Py3K
4. port and test ipython with Py3K
5. etc.

Given the PSF's stated emphasis this year, it probably doesn't make
sense to pursue any non-Py3K projects.

Jarrod

-- Forwarded message --
From: C. Titus Brown c...@msu.edu
Date: Tue, Mar 2, 2010 at 6:12 AM
Subject: [SoC2009-mentors] [...@msu.edu: GSoC 2010 - it's on!]
To: soc2009-ment...@python.org


- Forwarded message from C. Titus Brown c...@msu.edu -

Date: Wed, 24 Feb 2010 12:54:52 -0800
From: C. Titus Brown c...@msu.edu
To: psf-memb...@python.org
Cc: gsoc2010-ment...@python.org
Subject: GSoC 2010 - it's on!

Hi all,

it's that time of year again, and Google has decided to run the Google
Summer of Code again!

 http://groups.google.com/group/google-summer-of-code-discuss/browse_thread/thread/d839c0b02ac15b3f

 http://socghop.appspot.com/

Arc Riley has stepped up to run it for the PSF again this year, and I'm
backstopping him.  If you are interested in mentoring or kibbitzing on those
who are, please sign up for the soc2010-mentors mailing list here,

 http://mail.python.org/mailman/listinfo/soc2010-mentors

This year we're proposing to solicit and prioritize applications for
Python 3.x -- 3K tools, porting old projects, etc.  Python 2.x projects
will be a distinct second.  There will be no core category this year,
although obviously if someone on one of the core teams wants to push a
project it'll help!

If you have an idea for a project, please send it to the -mentors list and add
it to the wiki at

  http://wiki.python.org/moin/SummerOfCode/2010

We're also going to change a few things up to make it more useful to the PSF.
Specifically,

 - the foundation is going to *require* 1 blog post/wk from each student.

 - we're going to hire an administrative assistant to monitor the students.

 - the student application process will be a bit more rigorous and job-app
  like; the Django SF has been doing this for at least one round and they
  claim that it results in much better and more serious students.

 - we'll be focusing on student quality more than on project egalitarianism.
  If project X can recruit three fantastic students to one fantastic and one
  mediocre student for project Y, then project X gets three and project Y
  gets one.

The hope is that this will make the GSoC much more useful for Python than
it has been in the past.

Arc will be posting something to the www.python.org site and python-announce
soon, too.

Followups to soc2010-mentors.

cheers,
--titus
--
C. Titus Brown, c...@msu.edu

- End forwarded message -
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Is this a bug in numpy.ma.reduce?

2010-03-08 Thread Bruce Southey

On 03/08/2010 01:30 AM, David Goldsmith wrote:
On Sun, Mar 7, 2010 at 4:41 AM, Friedrich Romstedt 
friedrichromst...@gmail.com mailto:friedrichromst...@gmail.com wrote:


2010/3/5 Pierre GM pgmdevl...@gmail.com
mailto:pgmdevl...@gmail.com:
 'm'fraid no. I gonna have to investigate that. Please open a
ticket with a self-contained example that reproduces the issue.
 Thx in advance...
 P.

I would like to stress the fact that imo this is maybe not ticket
and not a bug.

The issue arises when calling a.max() or similar of empty arrays
a, i.e., with:

 0 in a.shape
True

Opposed to the .prod() of an empty array, such a .max() or .min()
cannot be defined, because the set is empty.  So it's fully correct to
let such calls fail.  Just the failure is a bit deep in numpy, and
only the traceback gives some hint what went wrong.

I posted something similar also on the matplotlib-users list, sorry
for cross-posting thus.


Any suggestions, then, how to go about figuring out what's happening 
in my code that's causing this feature to manifest itself?


DG


Perhaps providing the code with specific versions of Python, numpy etc. 
would help.


I would guess that aquarius_test.py has not correctly setup the 
necessary inputs (or has invalid inputs) required by matplotlib (which I 
have no knowledge about). Really you have to find if the _A in cmp.py 
used by 'self.norm.autoscale_None(self._A)' is valid. You may be missing 
a valid initialization step because the TypeError exception in 
autoscale_None ('You must first set_array for mappable') implies 
something need to be done first.


Bruce





___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Is this a bug in numpy.ma.reduce?

2010-03-08 Thread David Goldsmith
On Mon, Mar 8, 2010 at 6:52 AM, Bruce Southey bsout...@gmail.com wrote:

  On 03/08/2010 01:30 AM, David Goldsmith wrote:

 On Sun, Mar 7, 2010 at 4:41 AM, Friedrich Romstedt 
 friedrichromst...@gmail.com wrote:

 I would like to stress the fact that imo this is maybe not ticket and not
 a bug.

 The issue arises when calling a.max() or similar of empty arrays a, i.e.,
 with:

  0 in a.shape
 True

 Opposed to the .prod() of an empty array, such a .max() or .min()
 cannot be defined, because the set is empty.  So it's fully correct to
 let such calls fail.  Just the failure is a bit deep in numpy, and
 only the traceback gives some hint what went wrong.

 I posted something similar also on the matplotlib-users list, sorry
 for cross-posting thus.


 Any suggestions, then, how to go about figuring out what's happening in my
 code that's causing this feature to manifest itself?

 DG

 Perhaps providing the code with specific versions of Python, numpy etc.
 would help.

 I would guess that aquarius_test.py has not correctly setup the necessary
 inputs (or has invalid inputs) required by matplotlib (which I have no
 knowledge about). Really you have to find if the _A in cmp.py used by
 'self.norm.autoscale_None(self._A)' is valid. You may be missing a valid
 initialization step because the TypeError exception in autoscale_None ('You
 must first set_array for mappable') implies something need to be done first.


 Bruce


Python 2.5.4, Numpy 1.4.0, Matplotlib 0.99.0, Windows 32bit Vista Home
Premium SP2

# Code copyright 2010 by David Goldsmith
# Comments and unnecessaries edited for brevity
import numpy as N
import matplotlib as MPL
from matplotlib import pylab
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
import matplotlib.cm as cm

J = complex(0,1); tol = 1e-6; maxiter = 20;
roots = (-2 + J/2, -1 + J,  -0.5 + J/2, 0.5 + J,  1 + J/2, 2 + J, 2.5 + J/2,
 -2 - J,   -1 - J/2, -0.5 - J,  0.5 - J/2, 1 - J,  2 - J/2, 2.5 - J)

def ffp(z):
w, wp = (0J, 0J)
for root in roots:
z0 = z - root
w += N.sin(1/z0)
wp -= N.cos(1/z0)/(z0*z0)
return (w, wp)

def iter(z):
w, wp = ffp(z)
return z - w/wp

def find_root(z0):#, k, j):
count = 0
z1 = iter(z0)
if N.isnan(z1):
return N.complex64(N.inf)
while (N.abs(z1 - z0)  tol) and \
   (count  maxiter):
count += 1
z0 = z1
z1 = iter(z0)
if N.abs(z1 - z0)  tol:
result = 0
else:
result = z1
return N.complex64(result)

w, h, DPI = (3.2, 2.0, 100)
fig = Figure(figsize=(w, h),
 dpi=DPI,
 frameon=False)
ax = fig.add_subplot(1,1,1)
canvas = FigureCanvas(fig)
nx, xmin, xmax = (int(w*DPI), -0.5, 0.5)
ny, ymin, ymax = (int(h*DPI),  0.6, 1.2)

X, xincr = N.linspace(xmin,xmax,nx,retstep=True)
Y, yincr = N.linspace(ymin,ymax,ny,retstep=True)
W = N.zeros((ny,nx), dtype=N.complex64)

for j in N.arange(nx):
if not (j%100): # report progress
print j
for k in N.arange(ny):
x, y = (X[j], Y[k])
z0 = x + J*y
W[k,j] = find_root(z0)#,k,j)

print N.argwhere(N.logical_not(N.isfinite(W.real)))
print N.argwhere(N.logical_not(N.isfinite(W.imag)))
W = W.T
argW = N.angle(W)
print N.argwhere(N.logical_not(N.isfinite(argW)))
cms = (Blues,)# Blues_r, cool, cool_r,

def all_ticks_off(ax):
ax.xaxis.set_major_locator(pylab.NullLocator())
ax.yaxis.set_major_locator(pylab.NullLocator())

for cmap_name in cms:
all_ticks_off(ax)
ax.hold(True)
for i in range(4):
for j in range(4):
part2plot = argW[j*ny/4:(j+1)*ny/4, i*nx/4:(i+1)*nx/4]
if N.any(N.logical_not(N.isfinite(part2plot))):
print i, j,
print N.argwhere(N.logical_not(N.isfinite(part2plot)))
extent = (i*nx/4, (i+1)*nx/4, (j+1)*ny/4, j*ny/4)
ax.imshow(part2plot, cmap_name, extent = extent)
ax.set_xlim(0, nx)
ax.set_ylim(0, ny)
canvas.print_figure('../../Data-Figures/Zodiac/Aquarius/'+ cmap_name +
'Aquarius_test.png', dpi=DPI)
# End Aquarius_test.png

DG
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] printing structured arrays

2010-03-08 Thread Tim Michelsen
Hello,
I am also looking into the convertsion from strcutured arrays to ndarray.

 I've just started playing with numpy and have noticed that when printing
 a structured array that the output is not nicely formatted. Is there a
 way to make the formatting look the same as it does for an unstructured
 array?

 Output is:
 ### ndarray
 [[ 1.   2. ]
  [ 3.   4.1]]
 ### structured array
 [(1.0, 2.0) (3.0, 4.0996)]
How could we make this structured array look like the above shown
ndarray with shape (2, 2)?

Thanks for any additional hint,
Timmie

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] printing structured arrays

2010-03-08 Thread josef . pktd
On Mon, Mar 8, 2010 at 1:55 PM, Tim Michelsen
timmichel...@gmx-topmail.de wrote:
 Hello,
 I am also looking into the convertsion from strcutured arrays to ndarray.

 I've just started playing with numpy and have noticed that when printing
 a structured array that the output is not nicely formatted. Is there a
 way to make the formatting look the same as it does for an unstructured
 array?

 Output is:
 ### ndarray
 [[ 1.   2. ]
  [ 3.   4.1]]
 ### structured array
 [(1.0, 2.0) (3.0, 4.0996)]
 How could we make this structured array look like the above shown
 ndarray with shape (2, 2)?

.view(float) should do it, to created a ndarray view of the structured
array data

Josef


 Thanks for any additional hint,
 Timmie

 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] printing structured arrays

2010-03-08 Thread Skipper Seabold
On Mon, Mar 8, 2010 at 2:01 PM,  josef.p...@gmail.com wrote:
 On Mon, Mar 8, 2010 at 1:55 PM, Tim Michelsen
 timmichel...@gmx-topmail.de wrote:
 Hello,
 I am also looking into the convertsion from strcutured arrays to ndarray.

 I've just started playing with numpy and have noticed that when printing
 a structured array that the output is not nicely formatted. Is there a
 way to make the formatting look the same as it does for an unstructured
 array?

 Output is:
 ### ndarray
 [[ 1.   2. ]
  [ 3.   4.1]]
 ### structured array
 [(1.0, 2.0) (3.0, 4.0996)]
 How could we make this structured array look like the above shown
 ndarray with shape (2, 2)?

 .view(float) should do it, to created a ndarray view of the structured
 array data


Plus a reshape.  I usually know how many columns I have, so I put in
axis 1 and leave axis 0 as -1.

In [21]: a.view(float).reshape(-1,2)
Out[21]:
array([[ 1. ,  2. ],
   [ 3. ,  4.1]])


Skipper
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] printing structured arrays

2010-03-08 Thread josef . pktd
On Mon, Mar 8, 2010 at 2:04 PM, Skipper Seabold jsseab...@gmail.com wrote:
 On Mon, Mar 8, 2010 at 2:01 PM,  josef.p...@gmail.com wrote:
 On Mon, Mar 8, 2010 at 1:55 PM, Tim Michelsen
 timmichel...@gmx-topmail.de wrote:
 Hello,
 I am also looking into the convertsion from strcutured arrays to ndarray.

 I've just started playing with numpy and have noticed that when printing
 a structured array that the output is not nicely formatted. Is there a
 way to make the formatting look the same as it does for an unstructured
 array?

 Output is:
 ### ndarray
 [[ 1.   2. ]
  [ 3.   4.1]]
 ### structured array
 [(1.0, 2.0) (3.0, 4.0996)]
 How could we make this structured array look like the above shown
 ndarray with shape (2, 2)?

 .view(float) should do it, to created a ndarray view of the structured
 array data


 Plus a reshape.  I usually know how many columns I have, so I put in
 axis 1 and leave axis 0 as -1.

 In [21]: a.view(float).reshape(-1,2)
 Out[21]:
 array([[ 1. ,  2. ],
       [ 3. ,  4.1]])


a.view(float).reshape(len(a),-1) #if you don't want to count columns

I obviously haven't done this in a while.
And of course, it only works if all elements of the structured array
have the same type.

Josef


 Skipper
 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] printing structured arrays

2010-03-08 Thread Skipper Seabold
On Mon, Mar 8, 2010 at 2:17 PM,  josef.p...@gmail.com wrote:
 On Mon, Mar 8, 2010 at 2:04 PM, Skipper Seabold jsseab...@gmail.com wrote:
 On Mon, Mar 8, 2010 at 2:01 PM,  josef.p...@gmail.com wrote:
 On Mon, Mar 8, 2010 at 1:55 PM, Tim Michelsen
 timmichel...@gmx-topmail.de wrote:
 Hello,
 I am also looking into the convertsion from strcutured arrays to ndarray.

 I've just started playing with numpy and have noticed that when printing
 a structured array that the output is not nicely formatted. Is there a
 way to make the formatting look the same as it does for an unstructured
 array?

 Output is:
 ### ndarray
 [[ 1.   2. ]
  [ 3.   4.1]]
 ### structured array
 [(1.0, 2.0) (3.0, 4.0996)]
 How could we make this structured array look like the above shown
 ndarray with shape (2, 2)?

 .view(float) should do it, to created a ndarray view of the structured
 array data


 Plus a reshape.  I usually know how many columns I have, so I put in
 axis 1 and leave axis 0 as -1.

 In [21]: a.view(float).reshape(-1,2)
 Out[21]:
 array([[ 1. ,  2. ],
       [ 3. ,  4.1]])


 a.view(float).reshape(len(a),-1)     #if you don't want to count columns

 I obviously haven't done this in a while.
 And of course, it only works if all elements of the structured array
 have the same type.


For the archives with heterogeneous dtype.

import numpy as np

b = np.array([(1.0, 'string1', 2.0), (3.0, 'string2', 4.1)],
dtype=[('x', float),('str_var', 'a7'),('y',float)])

b[['x','y']].view(float).reshape(len(b),-1) # note the list within list syntax

#array([[ 1. ,  2. ],
#   [ 3. ,  4.1]])

Skipper
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Is this a bug in numpy.ma.reduce?

2010-03-08 Thread David Goldsmith
On Mon, Mar 8, 2010 at 10:17 AM, David Goldsmith d.l.goldsm...@gmail.comwrote:

 On Mon, Mar 8, 2010 at 6:52 AM, Bruce Southey bsout...@gmail.com wrote:

  On 03/08/2010 01:30 AM, David Goldsmith wrote:

 On Sun, Mar 7, 2010 at 4:41 AM, Friedrich Romstedt 
 friedrichromst...@gmail.com wrote:

 I would like to stress the fact that imo this is maybe not ticket and not
 a bug.

 The issue arises when calling a.max() or similar of empty arrays a, i.e.,
 with:

  0 in a.shape
 True

 Opposed to the .prod() of an empty array, such a .max() or .min()
 cannot be defined, because the set is empty.  So it's fully correct to
 let such calls fail.  Just the failure is a bit deep in numpy, and
 only the traceback gives some hint what went wrong.

 I posted something similar also on the matplotlib-users list, sorry
 for cross-posting thus.


 Any suggestions, then, how to go about figuring out what's happening in my
 code that's causing this feature to manifest itself?

 DG

 Perhaps providing the code with specific versions of Python, numpy etc.
 would help.

 I would guess that aquarius_test.py has not correctly setup the necessary
 inputs (or has invalid inputs) required by matplotlib (which I have no
 knowledge about). Really you have to find if the _A in cmp.py used by
 'self.norm.autoscale_None(self._A)' is valid. You may be missing a valid
 initialization step because the TypeError exception in autoscale_None ('You
 must first set_array for mappable') implies something need to be done first.


 Bruce


 Python 2.5.4, Numpy 1.4.0, Matplotlib 0.99.0, Windows 32bit Vista Home
 Premium SP2

 # Code copyright 2010 by David Goldsmith
 # Comments and unnecessaries edited for brevity
 import numpy as N
 import matplotlib as MPL
 from matplotlib import pylab
 from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
 from matplotlib.figure import Figure
 import matplotlib.cm as cm

 J = complex(0,1); tol = 1e-6; maxiter = 20;
 roots = (-2 + J/2, -1 + J,  -0.5 + J/2, 0.5 + J,  1 + J/2, 2 + J, 2.5 +
 J/2,
  -2 - J,   -1 - J/2, -0.5 - J,  0.5 - J/2, 1 - J,  2 - J/2, 2.5 -
 J)

 def ffp(z):
 w, wp = (0J, 0J)
 for root in roots:
 z0 = z - root
 w += N.sin(1/z0)
 wp -= N.cos(1/z0)/(z0*z0)
 return (w, wp)

 def iter(z):
 w, wp = ffp(z)
 return z - w/wp

 def find_root(z0):#, k, j):
 count = 0
 z1 = iter(z0)
 if N.isnan(z1):
 return N.complex64(N.inf)
 while (N.abs(z1 - z0)  tol) and \
(count  maxiter):
 count += 1
 z0 = z1
 z1 = iter(z0)
 if N.abs(z1 - z0)  tol:
 result = 0
 else:
 result = z1
 return N.complex64(result)

 w, h, DPI = (3.2, 2.0, 100)
 fig = Figure(figsize=(w, h),
  dpi=DPI,
  frameon=False)
 ax = fig.add_subplot(1,1,1)
 canvas = FigureCanvas(fig)
 nx, xmin, xmax = (int(w*DPI), -0.5, 0.5)
 ny, ymin, ymax = (int(h*DPI),  0.6, 1.2)

 X, xincr = N.linspace(xmin,xmax,nx,retstep=True)
 Y, yincr = N.linspace(ymin,ymax,ny,retstep=True)
 W = N.zeros((ny,nx), dtype=N.complex64)

 for j in N.arange(nx):
 if not (j%100): # report progress
 print j
 for k in N.arange(ny):
 x, y = (X[j], Y[k])
 z0 = x + J*y
 W[k,j] = find_root(z0)#,k,j)

 print N.argwhere(N.logical_not(N.isfinite(W.real)))
 print N.argwhere(N.logical_not(N.isfinite(W.imag)))
 W = W.T
 argW = N.angle(W)
 print N.argwhere(N.logical_not(N.isfinite(argW)))
 cms = (Blues,)# Blues_r, cool, cool_r,

 def all_ticks_off(ax):
 ax.xaxis.set_major_locator(pylab.NullLocator())
 ax.yaxis.set_major_locator(pylab.NullLocator())

 for cmap_name in cms:
 all_ticks_off(ax)
 ax.hold(True)
 for i in range(4):
 for j in range(4):
 part2plot = argW[j*ny/4:(j+1)*ny/4, i*nx/4:(i+1)*nx/4]
 if N.any(N.logical_not(N.isfinite(part2plot))):
 print i, j,
 print N.argwhere(N.logical_not(N.isfinite(part2plot)))
 extent = (i*nx/4, (i+1)*nx/4, (j+1)*ny/4, j*ny/4)

 ax.imshow(part2plot, cmap_name, extent = extent)
 ax.set_xlim(0, nx)
 ax.set_ylim(0, ny)
 canvas.print_figure('../../Data-Figures/Zodiac/Aquarius/'+ cmap_name +
 'Aquarius_test.png', dpi=DPI)
 # End Aquarius_test.png

 DG


Oh, and here's fresh output (i.e., I just reran it to confirm that I'm
still having the problem).
0
100
200
300
[[133 319]]
[]
[]
Traceback (most recent call last):
File
C:\Users\Fermat\Documents\Fractals\Python\Source\Zodiac\aquarius_test.py,
line 108, in module
ax.imshow(part2plot, cmap_name, extent = extent)
File C:\Python254\lib\site-packages\matplotlib\axes.py, line 6261, in
imshow
im.autoscale_None()
File C:\Python254\lib\site-packages\matplotlib\cm.py, line 236, in
autoscale_None
self.norm.autoscale_None(self._A)
File C:\Python254\lib\site-packages\matplotlib\colors.py, line 792, in
autoscale_None
if self.vmin is None: self.vmin = 

Re: [Numpy-discussion] Is this a bug in numpy.ma.reduce?

2010-03-08 Thread Friedrich Romstedt
It's pretty simple, but I was stunned myself how simple.  Have a look
at line 65 of your script you provided:

W = W.T

This means,  x - y.  But in the for loops, you still act as if W
wasn't transposed.  I added some prints, the positions should be clear
for you:

argW.shape = (320, 200)
i, j = (0, 0)
j*ny/4, (j+1)*ny/4, i*nx/4, (i+1)*nx/4 = (0, 50, 0, 80)
part2plot.shape = (50, 80)
i, j = (0, 1)
j*ny/4, (j+1)*ny/4, i*nx/4, (i+1)*nx/4 = (50, 100, 0, 80)
part2plot.shape = (50, 80)
i, j = (0, 2)
j*ny/4, (j+1)*ny/4, i*nx/4, (i+1)*nx/4 = (100, 150, 0, 80)
part2plot.shape = (50, 80)
i, j = (0, 3)
j*ny/4, (j+1)*ny/4, i*nx/4, (i+1)*nx/4 = (150, 200, 0, 80)
part2plot.shape = (50, 80)
i, j = (1, 0)
j*ny/4, (j+1)*ny/4, i*nx/4, (i+1)*nx/4 = (0, 50, 80, 160)
part2plot.shape = (50, 80)
i, j = (1, 1)
j*ny/4, (j+1)*ny/4, i*nx/4, (i+1)*nx/4 = (50, 100, 80, 160)
part2plot.shape = (50, 80)
i, j = (1, 2)
j*ny/4, (j+1)*ny/4, i*nx/4, (i+1)*nx/4 = (100, 150, 80, 160)
part2plot.shape = (50, 80)
i, j = (1, 3)
j*ny/4, (j+1)*ny/4, i*nx/4, (i+1)*nx/4 = (150, 200, 80, 160)
part2plot.shape = (50, 80)
i, j = (2, 0)
j*ny/4, (j+1)*ny/4, i*nx/4, (i+1)*nx/4 = (0, 50, 160, 240)
part2plot.shape = (50, 40)
i, j = (2, 1)
j*ny/4, (j+1)*ny/4, i*nx/4, (i+1)*nx/4 = (50, 100, 160, 240)
part2plot.shape = (50, 40)
i, j = (2, 2)
j*ny/4, (j+1)*ny/4, i*nx/4, (i+1)*nx/4 = (100, 150, 160, 240)
part2plot.shape = (50, 40)
i, j = (2, 3)
j*ny/4, (j+1)*ny/4, i*nx/4, (i+1)*nx/4 = (150, 200, 160, 240)
part2plot.shape = (50, 40)
i, j = (3, 0)
j*ny/4, (j+1)*ny/4, i*nx/4, (i+1)*nx/4 = (0, 50, 240, 320)
part2plot.shape = (50, 0)
Traceback (most recent call last):
  File D:\Home\Friedrich\Entwicklung\2010\David\aquarius.py, line 91, in ?
ax.imshow(part2plot, extent = extent)
  File D:\Programme\Programmierung\python-2.4.1\lib\site-packages\matplotlib\ax
es.py, line 5471, in imshow
im.autoscale_None()
  File D:\Programme\Programmierung\python-2.4.1\lib\site-packages\matplotlib\cm
.py, line 148, in autoscale_None
self.norm.autoscale_None(self._A)
  File D:\Programme\Programmierung\python-2.4.1\lib\site-packages\matplotlib\co
lors.py, line 682, in autoscale_None
if self.vmin is None: self.vmin = ma.minimum(A)
  File D:\Programme\Programmierung\python-2.4.1\lib\site-packages\numpy\ma\core
.py, line 3042, in __call__
return self.reduce(a)
  File D:\Programme\Programmierung\python-2.4.1\lib\site-packages\numpy\ma\core
.py, line 3057, in reduce
t = self.ufunc.reduce(target, **kargs)
ValueError: zero-size array to ufunc.reduce without identity

So you simply have to exchange the role of x and y in your slice
indicing expression, and everything will work out fine, I suspect :-)

Or simpy leave out the transposition?  Note that in the other case,
you also may have to consider to change to extent's axes to get it
properly reflected.

NB: With my version of matplotlib, it didn't accept the colormap, but
when yours does, it doesn't matter.

Friedrich
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] printing structured arrays

2010-03-08 Thread josef . pktd
On Mon, Mar 8, 2010 at 2:24 PM, Skipper Seabold jsseab...@gmail.com wrote:
 On Mon, Mar 8, 2010 at 2:17 PM,  josef.p...@gmail.com wrote:
 On Mon, Mar 8, 2010 at 2:04 PM, Skipper Seabold jsseab...@gmail.com wrote:
 On Mon, Mar 8, 2010 at 2:01 PM,  josef.p...@gmail.com wrote:
 On Mon, Mar 8, 2010 at 1:55 PM, Tim Michelsen
 timmichel...@gmx-topmail.de wrote:
 Hello,
 I am also looking into the convertsion from strcutured arrays to ndarray.

 I've just started playing with numpy and have noticed that when printing
 a structured array that the output is not nicely formatted. Is there a
 way to make the formatting look the same as it does for an unstructured
 array?

 Output is:
 ### ndarray
 [[ 1.   2. ]
  [ 3.   4.1]]
 ### structured array
 [(1.0, 2.0) (3.0, 4.0996)]
 How could we make this structured array look like the above shown
 ndarray with shape (2, 2)?

 .view(float) should do it, to created a ndarray view of the structured
 array data


 Plus a reshape.  I usually know how many columns I have, so I put in
 axis 1 and leave axis 0 as -1.

 In [21]: a.view(float).reshape(-1,2)
 Out[21]:
 array([[ 1. ,  2. ],
       [ 3. ,  4.1]])


 a.view(float).reshape(len(a),-1)     #if you don't want to count columns

 I obviously haven't done this in a while.
 And of course, it only works if all elements of the structured array
 have the same type.


 For the archives with heterogeneous dtype.

 import numpy as np

 b = np.array([(1.0, 'string1', 2.0), (3.0, 'string2', 4.1)],
 dtype=[('x', float),('str_var', 'a7'),('y',float)])

 b[['x','y']].view(float).reshape(len(b),-1) # note the list within list syntax

 #array([[ 1. ,  2. ],
 #       [ 3. ,  4.1]])

nice, I've never seen selection of multiple columns before. I didn't
know it is possible to get a subset of columns this way

 b[['x','y']]
array([(1.0, 2.0), (3.0, 4.0996)],
  dtype=[('x', 'f8'), ('y', 'f8')])
 b['x']
array([ 1.,  3.])
 b[['x']]
array([(1.0,), (3.0,)],
  dtype=[('x', 'f8')])

Josef



 Skipper
 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Is this a bug in numpy.ma.reduce?

2010-03-08 Thread Bruce Southey

On 03/08/2010 12:17 PM, David Goldsmith wrote:
On Mon, Mar 8, 2010 at 6:52 AM, Bruce Southey bsout...@gmail.com 
mailto:bsout...@gmail.com wrote:


On 03/08/2010 01:30 AM, David Goldsmith wrote:

On Sun, Mar 7, 2010 at 4:41 AM, Friedrich Romstedt
friedrichromst...@gmail.com
mailto:friedrichromst...@gmail.com wrote:

I would like to stress the fact that imo this is maybe not
ticket and not a bug.

The issue arises when calling a.max() or similar of empty
arrays a, i.e., with:

 0 in a.shape
True

Opposed to the .prod() of an empty array, such a .max() or .min()
cannot be defined, because the set is empty.  So it's fully
correct to
let such calls fail.  Just the failure is a bit deep in
numpy, and
only the traceback gives some hint what went wrong.

I posted something similar also on the matplotlib-users list,
sorry
for cross-posting thus.


Any suggestions, then, how to go about figuring out what's
happening in my code that's causing this feature to manifest
itself?

DG

Perhaps providing the code with specific versions of Python, numpy
etc. would help.

I would guess that aquarius_test.py has not correctly setup the
necessary inputs (or has invalid inputs) required by matplotlib
(which I have no knowledge about). Really you have to find if the
_A in cmp.py used by 'self.norm.autoscale_None(self._A)' is valid.
You may be missing a valid initialization step because the
TypeError exception in autoscale_None ('You must first set_array
for mappable') implies something need to be done first.

Bruce


Python 2.5.4, Numpy 1.4.0, Matplotlib 0.99.0, Windows 32bit Vista Home 
Premium SP2


# Code copyright 2010 by David Goldsmith
# Comments and unnecessaries edited for brevity
import numpy as N
import matplotlib as MPL
from matplotlib import pylab
from matplotlib.backends.backend_agg import FigureCanvasAgg as 
FigureCanvas

from matplotlib.figure import Figure
import matplotlib.cm http://matplotlib.cm as cm

J = complex(0,1); tol = 1e-6; maxiter = 20;
roots = (-2 + J/2, -1 + J,  -0.5 + J/2, 0.5 + J,  1 + J/2, 2 + J, 2.5 
+ J/2,
 -2 - J,   -1 - J/2, -0.5 - J,  0.5 - J/2, 1 - J,  2 - J/2, 
2.5 - J)


def ffp(z):
w, wp = (0J, 0J)
for root in roots:
z0 = z - root
w += N.sin(1/z0)
wp -= N.cos(1/z0)/(z0*z0)
return (w, wp)

def iter(z):
w, wp = ffp(z)
return z - w/wp

def find_root(z0):#, k, j):
count = 0
z1 = iter(z0)
if N.isnan(z1):
return N.complex64(N.inf)
while (N.abs(z1 - z0)  tol) and \
   (count  maxiter):
count += 1
z0 = z1
z1 = iter(z0)
if N.abs(z1 - z0)  tol:
result = 0
else:
result = z1
return N.complex64(result)

w, h, DPI = (3.2, 2.0, 100)
fig = Figure(figsize=(w, h),
 dpi=DPI,
 frameon=False)
ax = fig.add_subplot(1,1,1)
canvas = FigureCanvas(fig)
nx, xmin, xmax = (int(w*DPI), -0.5, 0.5)
ny, ymin, ymax = (int(h*DPI),  0.6, 1.2)

X, xincr = N.linspace(xmin,xmax,nx,retstep=True)
Y, yincr = N.linspace(ymin,ymax,ny,retstep=True)
W = N.zeros((ny,nx), dtype=N.complex64)

for j in N.arange(nx):
if not (j%100): # report progress
print j
for k in N.arange(ny):
x, y = (X[j], Y[k])
z0 = x + J*y
W[k,j] = find_root(z0)#,k,j)

print N.argwhere(N.logical_not(N.isfinite(W.real)))
print N.argwhere(N.logical_not(N.isfinite(W.imag)))
W = W.T
argW = N.angle(W)
print N.argwhere(N.logical_not(N.isfinite(argW)))
cms = (Blues,)# Blues_r, cool, cool_r,

def all_ticks_off(ax):
ax.xaxis.set_major_locator(pylab.NullLocator())
ax.yaxis.set_major_locator(pylab.NullLocator())

for cmap_name in cms:
all_ticks_off(ax)
ax.hold(True)
for i in range(4):
for j in range(4):
part2plot = argW[j*ny/4:(j+1)*ny/4, i*nx/4:(i+1)*nx/4]
if N.any(N.logical_not(N.isfinite(part2plot))):
print i, j,
print N.argwhere(N.logical_not(N.isfinite(part2plot)))
extent = (i*nx/4, (i+1)*nx/4, (j+1)*ny/4, j*ny/4)
ax.imshow(part2plot, cmap_name, extent = extent)
ax.set_xlim(0, nx)
ax.set_ylim(0, ny)
canvas.print_figure('../../Data-Figures/Zodiac/Aquarius/'+ cmap_name +
'Aquarius_test.png', dpi=DPI)
# End Aquarius_test.png

DG


___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion
   

Hmm,
Appears that you have mixed your indices when creating part2plot. If you 
this line instead it works:

part2plot = argW[j*nx/4:(j+1)*nx/4, i*ny/4:(i+1)*ny/4]


I found that by looking the shape of the part2plot array that is 
component of the argW array.


The shape of argW is (320, 200). So in your loops to find part2plot you 

Re: [Numpy-discussion] Is this a bug in numpy.ma.reduce?

2010-03-08 Thread Friedrich Romstedt
2010/3/8 Bruce Southey bsout...@gmail.com:
 Hmm,
 Appears that you have mixed your indices when creating part2plot. If you
 this line instead it works:
 part2plot = argW[j*nx/4:(j+1)*nx/4, i*ny/4:(i+1)*ny/4]


 I found that by looking the shape of the part2plot array that is component
 of the argW array.

 The shape of argW is (320, 200). So in your loops to find part2plot you
 eventually exceed 200 and eventually the index to the second axis is greater
 than 200 causing everything to crash:
 When i=0 or 1 then the shape of part2plot is (50, 80)
 when i=2 then the shape of part2plot is (50, 40)
 when i=3 then the shape of part2plot is (50,  0) # crash

Nice that we have found this out both at the same instance of time
(with 5min precision) :-)

Friedrich
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Is this a bug in numpy.ma.reduce?

2010-03-08 Thread David Goldsmith
How embarrassing! :O  Well, as they say, 'nother set of eyes...

Thanks!

DG

On Mon, Mar 8, 2010 at 11:25 AM, Friedrich Romstedt 
friedrichromst...@gmail.com wrote:

 It's pretty simple, but I was stunned myself how simple.  Have a look
 at line 65 of your script you provided:

 W = W.T

 This means,  x - y.  But in the for loops, you still act as if W
 wasn't transposed.  I added some prints, the positions should be clear
 for you:

 argW.shape = (320, 200)
 i, j = (0, 0)
 j*ny/4, (j+1)*ny/4, i*nx/4, (i+1)*nx/4 = (0, 50, 0, 80)
 part2plot.shape = (50, 80)
 i, j = (0, 1)
 j*ny/4, (j+1)*ny/4, i*nx/4, (i+1)*nx/4 = (50, 100, 0, 80)
 part2plot.shape = (50, 80)
 i, j = (0, 2)
 j*ny/4, (j+1)*ny/4, i*nx/4, (i+1)*nx/4 = (100, 150, 0, 80)
 part2plot.shape = (50, 80)
 i, j = (0, 3)
 j*ny/4, (j+1)*ny/4, i*nx/4, (i+1)*nx/4 = (150, 200, 0, 80)
 part2plot.shape = (50, 80)
 i, j = (1, 0)
 j*ny/4, (j+1)*ny/4, i*nx/4, (i+1)*nx/4 = (0, 50, 80, 160)
 part2plot.shape = (50, 80)
 i, j = (1, 1)
 j*ny/4, (j+1)*ny/4, i*nx/4, (i+1)*nx/4 = (50, 100, 80, 160)
 part2plot.shape = (50, 80)
 i, j = (1, 2)
 j*ny/4, (j+1)*ny/4, i*nx/4, (i+1)*nx/4 = (100, 150, 80, 160)
 part2plot.shape = (50, 80)
 i, j = (1, 3)
 j*ny/4, (j+1)*ny/4, i*nx/4, (i+1)*nx/4 = (150, 200, 80, 160)
 part2plot.shape = (50, 80)
 i, j = (2, 0)
 j*ny/4, (j+1)*ny/4, i*nx/4, (i+1)*nx/4 = (0, 50, 160, 240)
 part2plot.shape = (50, 40)
 i, j = (2, 1)
 j*ny/4, (j+1)*ny/4, i*nx/4, (i+1)*nx/4 = (50, 100, 160, 240)
 part2plot.shape = (50, 40)
 i, j = (2, 2)
 j*ny/4, (j+1)*ny/4, i*nx/4, (i+1)*nx/4 = (100, 150, 160, 240)
 part2plot.shape = (50, 40)
 i, j = (2, 3)
 j*ny/4, (j+1)*ny/4, i*nx/4, (i+1)*nx/4 = (150, 200, 160, 240)
 part2plot.shape = (50, 40)
 i, j = (3, 0)
 j*ny/4, (j+1)*ny/4, i*nx/4, (i+1)*nx/4 = (0, 50, 240, 320)
 part2plot.shape = (50, 0)
 Traceback (most recent call last):
   File D:\Home\Friedrich\Entwicklung\2010\David\aquarius.py, line 91, in
 ?
ax.imshow(part2plot, extent = extent)
  File
 D:\Programme\Programmierung\python-2.4.1\lib\site-packages\matplotlib\ax
 es.py, line 5471, in imshow
im.autoscale_None()
  File
 D:\Programme\Programmierung\python-2.4.1\lib\site-packages\matplotlib\cm
 .py, line 148, in autoscale_None
 self.norm.autoscale_None(self._A)
   File
 D:\Programme\Programmierung\python-2.4.1\lib\site-packages\matplotlib\co
 lors.py, line 682, in autoscale_None
 if self.vmin is None: self.vmin = ma.minimum(A)
   File
 D:\Programme\Programmierung\python-2.4.1\lib\site-packages\numpy\ma\core
 .py, line 3042, in __call__
return self.reduce(a)
  File
 D:\Programme\Programmierung\python-2.4.1\lib\site-packages\numpy\ma\core
 .py, line 3057, in reduce
 t = self.ufunc.reduce(target, **kargs)
 ValueError: zero-size array to ufunc.reduce without identity

 So you simply have to exchange the role of x and y in your slice
 indicing expression, and everything will work out fine, I suspect :-)

 Or simpy leave out the transposition?  Note that in the other case,
 you also may have to consider to change to extent's axes to get it
 properly reflected.

 NB: With my version of matplotlib, it didn't accept the colormap, but
 when yours does, it doesn't matter.

 Friedrich
 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] printing structured arrays

2010-03-08 Thread Pierre GM
On Mar 8, 2010, at 1:55 PM, Tim Michelsen wrote:
 Hello,
 I am also looking into the convertsion from strcutured arrays to ndarray.
 
 I've just started playing with numpy and have noticed that when printing
 a structured array that the output is not nicely formatted. Is there a
 way to make the formatting look the same as it does for an unstructured
 array?
 
 Output is:
 ### ndarray
 [[ 1.   2. ]
 [ 3.   4.1]]
 ### structured array
 [(1.0, 2.0) (3.0, 4.0996)]
 How could we make this structured array look like the above shown
 ndarray with shape (2, 2)?


if you're 100% sure all your fields have the same dtype (float), 
``a.view((float,2))`` is the simplest. Note the tuple (dtype, 
len(a.dtype.names)).
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] PSF GSoC 2010 (Py3K focus)

2010-03-08 Thread Jarrod Millman
I added Titus' email regarding the PSF's focus on Py3K-related
projects to our SoC ideas wiki page:
http://projects.scipy.org/scipy/wiki/SummerofCodeIdeas

Given Titus' email, this is the most likely list of projects we will
get accepted this year:

- finish porting NumPy to Py3K
- port SciPy to Py3K
- port matplotlib to Py3K
- port ipython to Py3K

Given that we know what projects we will likely have accepted, it is
worth starting to flesh these proposals out in detail.  Also, we
should start discussing how we will choose which student's we want to
work on these ports.  In particular, we should list what skills and
background will be necessary to successfully complete these ports.

Thoughts? Ideas?

Best,
Jarrod
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] PSF GSoC 2010 (Py3K focus)

2010-03-08 Thread Charles R Harris
On Mon, Mar 8, 2010 at 10:29 PM, Jarrod Millman mill...@berkeley.eduwrote:

 I added Titus' email regarding the PSF's focus on Py3K-related
 projects to our SoC ideas wiki page:
 http://projects.scipy.org/scipy/wiki/SummerofCodeIdeas

 Given Titus' email, this is the most likely list of projects we will
 get accepted this year:

 - finish porting NumPy to Py3K


I think Numpy is pretty much done. It needs use testing to wring out any
small oddities, but it doesn't look to me like a GSOC project at the moment.
Maybe Pauli can weigh in here.


 - port SciPy to Py3K


This project might be more appropriate, although I'm not clear on what needs
to be done.


 - port matplotlib to Py3K
 - port ipython to Py3K


Chuck
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion