Re: [Numpy-discussion] Sine Distribution on a 2D Array
Am 25.07.10 06:38, schrieb Ian Mallett: Hi, So I have a square 2D array, and I want to fill the array with sine values. The values need to be generated by their coordinates within the array. The center of the array should be treated as the angle 90 degrees. Each of the four edges should be 0 degrees. The corners, therefore, ought to be -sqrt(2)*90 degrees. The angle is equal to (distance_from_center/(dimension_of_array/2))*90 degrees. Then take the sine of this angle. To describe another way, if the array is treated like a height-field, a single mound of the sine wave should just fit inside the array. Right now, I'm having trouble because I don't know how to operate on an array's values based on the index of the values themselves. Something like that? The mgrid thing returns two 2D arrays containing the x- and y-coordinates which are then used to calculate the height field. In [5]: import numpy as N In [6]: x,y = N.mgrid[-N.pi/2.0:N.pi/2.0:100j,-N.pi/2.0:N.pi/2.0:100j] In [7]: z = N.sin(N.sqrt(x**2+y**2)) Christian ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Sine Distribution on a 2D Array
Hi, After much deliberation, I found a passable solution: distances = np.abs(np.arange(0,resolution,1)+0.5-(resolution/2.0)) x_gradient = np.tile(distances,(resolution,1)) y_gradient = np.copy(x_gradient) y_gradient = np.swapaxes(y_gradient,0,1) distances_to_center = np.hypot(x_gradient,y_gradient) angles = np.radians( (distances_to_center/((resolution/2.0)-0.5)) * 90.0 ) lambert_weights = np.cos(angles) This seems like it could be improved. Ian PS, I meant Sinusoidal in the title. I carried that over into my description, which should have been cosine, instead of sine. ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] Problem using polyutils.mapdomain with fromfunction
Why am I being told my coefficient array is not 1-d when both coefficient arrays--old and new--are reported to have shape (2L,): C:\Users\Fermatpython Python 2.6.5 (r265:79096, Mar 19 2010, 18:02:59) [MSC v.1500 64 bit (AMD64)] on win32 Type help, copyright, credits or license for more information. import numpy as np np.version.version '1.4.1' from numpy.polynomial import polyutils as pu nx = 1 ny = 1 def whydoesntthiswork(x, y): ... old = np.array((0,2)); print old.shape ... new = np.array((-1,1)); print new.shape ... X = pu.mapdomain(x, old, new) ... return X ... result = np.fromfunction(whydoesntthiswork, (nx, ny)) (2L,) (2L,) Traceback (most recent call last): File stdin, line 1, in module File C:\Python26\lib\site-packages\numpy\core\numeric.py, line 1539, in from function return function(*args,**kwargs) File stdin, line 4, in whydoesntthiswork File C:\Python26\lib\site-packages\numpy\polynomial\polyutils.py, line 280, in mapdomain [x] = as_series([x], trim=False) File C:\Python26\lib\site-packages\numpy\polynomial\polyutils.py, line 139, in as_series raise ValueError(Coefficient array is not 1-d) ValueError: Coefficient array is not 1-d Thanks in advance, DG ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] numpy.append and persisting original datatype
Hello, After a little more research, I can see that as a work around is: foo = np.append(foo, np.asanyarray([1., 2., 3.], dtype=foo.dtype)) It seems that within numpy.append(), the call to ravel() (numpy/ function.base.py [line 3490]) produces an array with a dtype that best fits. In this case it is float64 (when my original array was float32). Best wishes ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] segmentation fault when installing with pip and python2.7
On Sat, Jul 24, 2010 at 8:38 PM, David Cournapeau wrote: In general, because the packaging/build infrastructure in python is horrible. However, in this precise case, the issue is simply that numpy 1.4.1 does not support python2.7. How about a tiny update to the numpy 1.4.x on PyPi which checks for Python 2.7 and aborts with a message suggesting waiting for NumPy 1.5.x or using Python 2.6 instead? Peter ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Problem using polyutils.mapdomain with fromfunction
On Sun, Jul 25, 2010 at 2:32 AM, David Goldsmith d.l.goldsm...@gmail.comwrote: Why am I being told my coefficient array is not 1-d when both coefficient arrays--old and new--are reported to have shape (2L,): C:\Users\Fermatpython Python 2.6.5 (r265:79096, Mar 19 2010, 18:02:59) [MSC v.1500 64 bit (AMD64)] on win32 Type help, copyright, credits or license for more information. import numpy as np np.version.version '1.4.1' from numpy.polynomial import polyutils as pu nx = 1 ny = 1 def whydoesntthiswork(x, y): ... old = np.array((0,2)); print old.shape ... new = np.array((-1,1)); print new.shape ... X = pu.mapdomain(x, old, new) ... return X ... result = np.fromfunction(whydoesntthiswork, (nx, ny)) (2L,) (2L,) Traceback (most recent call last): File stdin, line 1, in module File C:\Python26\lib\site-packages\numpy\core\numeric.py, line 1539, in from function return function(*args,**kwargs) File stdin, line 4, in whydoesntthiswork File C:\Python26\lib\site-packages\numpy\polynomial\polyutils.py, line 280, in mapdomain [x] = as_series([x], trim=False) File C:\Python26\lib\site-packages\numpy\polynomial\polyutils.py, line 139, in as_series raise ValueError(Coefficient array is not 1-d) ValueError: Coefficient array is not 1-d Thanks in advance, Because fromfunction passes 2d arrays to whydoesntthiswork and mapdomain doesn't accept 2d arrays as the first argument. That looks like an unnecessary restriction, open a ticket and I'll fix it up. Chuck ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] np.fromstring and Python 3
Hi, The following example illustrates a problem I'm encountering a problem with the np.fromstring function in Python 3: Python 3.1.2 (r312:79360M, Mar 24 2010, 01:33:18) [GCC 4.0.1 (Apple Inc. build 5493)] on darwin Type help, copyright, credits or license for more information. import numpy as np string = .join(chr(i) for i in range(256)) a = np.fromstring(string, dtype=np.int8) print(len(string)) 256 print(len(a)) 384 The array 'a' should have the same size as 'string' since I'm using a 1-byte datatype. Is this a bug, or do I need to change the way I use this function in Python 3? I am using Numpy r8523 Cheers, Tom ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Problem using polyutils.mapdomain with fromfunction
On Sun, Jul 25, 2010 at 7:08 AM, Charles R Harris charlesr.har...@gmail.com wrote: On Sun, Jul 25, 2010 at 2:32 AM, David Goldsmith d.l.goldsm...@gmail.comwrote: Why am I being told my coefficient array is not 1-d when both coefficient arrays--old and new--are reported to have shape (2L,): C:\Users\Fermatpython Python 2.6.5 (r265:79096, Mar 19 2010, 18:02:59) [MSC v.1500 64 bit (AMD64)] on win32 Type help, copyright, credits or license for more information. import numpy as np np.version.version '1.4.1' from numpy.polynomial import polyutils as pu nx = 1 ny = 1 def whydoesntthiswork(x, y): ... old = np.array((0,2)); print old.shape ... new = np.array((-1,1)); print new.shape ... X = pu.mapdomain(x, old, new) ... return X ... result = np.fromfunction(whydoesntthiswork, (nx, ny)) (2L,) (2L,) Traceback (most recent call last): File stdin, line 1, in module File C:\Python26\lib\site-packages\numpy\core\numeric.py, line 1539, in from function return function(*args,**kwargs) File stdin, line 4, in whydoesntthiswork File C:\Python26\lib\site-packages\numpy\polynomial\polyutils.py, line 280, in mapdomain [x] = as_series([x], trim=False) File C:\Python26\lib\site-packages\numpy\polynomial\polyutils.py, line 139, in as_series raise ValueError(Coefficient array is not 1-d) ValueError: Coefficient array is not 1-d Thanks in advance, Because fromfunction passes 2d arrays to whydoesntthiswork and mapdomain doesn't accept 2d arrays as the first argument. That looks like an unnecessary restriction, open a ticket and I'll fix it up. Thanks, Chuck. DG Chuck ___ 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] np.fromstring and Python 3
Sun, 25 Jul 2010 10:17:53 -0400, Thomas Robitaille wrote: The following example illustrates a problem I'm encountering a problem with the np.fromstring function in Python 3: Python 3.1.2 (r312:79360M, Mar 24 2010, 01:33:18) [GCC 4.0.1 (Apple Inc. build 5493)] on darwin Type help, copyright, credits or license for more information. import numpy as np string = .join(chr(i) for i in range(256)) a = np.fromstring(string, dtype=np.int8) print(len(string)) 256 print(len(a)) 384 The array 'a' should have the same size as 'string' since I'm using a 1-byte datatype. Is this a bug, or do I need to change the way I use this function in Python 3? That's a bug. It apparently implicitly encodes the Unicode string you pass in to UTF-8, instead of trying to encode in ASCII and fail, like it does on Python 2: np.fromstring(\xe4.decode('latin1'), dtype=np.int8) Traceback (most recent call last): File stdin, line 1, in module UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in position 0: ordinal not in range(128) You probably meant to use byte strings, though: string = b.join(chr(i).encode('latin1') for i in range(256)) -- Pauli Virtanen ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Arrays of Python Values
Hi, I've converted all of the code to use record arrays, for a 10-fold speed boost. Thanks, Ian ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] First shot at svn-git conversion
Hi there, I have finally prepared and uploaded a test repository containing numpy code: http://github.com/numpy/numpy_svn Please check in particular that your account information are correctly recorded in the log. A few informations: - the repo was converted from a local svn mirror to git through svn-all-fast-export - svn tags are put into the svntags namespace, and only maintenance branches have been kept - out of branch branches (f2py, vendor, etc...) have not been included. They become separate git repos (not uploaded). DO NOT COMMIT ANYTHING TO THIS REPO - this is only for testing, any change made to this repo WILL be lost, cheers, David ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion