Re: [Numpy-discussion] array from list of lists

2006-11-13 Thread Stefan van der Walt
On Mon, Nov 13, 2006 at 02:29:11PM -0700, Tim Hochberg wrote: Erin Sheldon wrote: On 11/13/06, Tim Hochberg [EMAIL PROTECTED] wrote: Here's one more approach that's marginally faster than the map based solution and also won't chew up an extra memory since it's based on from iter:

Re: [Numpy-discussion] Assign NaN, get zero

2006-11-11 Thread Stefan van der Walt
On Sat, Nov 11, 2006 at 10:40:22AM -0800, Keith Goodman wrote: I accidentally wrote a unit test using int32 instead of float64 and ran into this problem: x = M.matrix([[1, 2, 3]]) x[0,1] = M.nan x matrix([[1, 0, 3]]) --- Got 0 instead of NaN But this, of course, works: x =

Re: [Numpy-discussion] Assign NaN, get zero

2006-11-11 Thread Stefan van der Walt
On Sat, Nov 11, 2006 at 06:30:06PM -0300, Lisandro Dalcin wrote: On 11/11/06, Stefan van der Walt [EMAIL PROTECTED] wrote: NaN (or inf) is a floating point number, so seeing a zero in integer representation seems correct: In [2]: int(N.nan) Out[2]: 0L Just to learn myself: Why int

Re: [Numpy-discussion] Assign NaN, get zero

2006-11-11 Thread Stefan van der Walt
On Sat, Nov 11, 2006 at 01:59:40PM -0800, Keith Goodman wrote: Would it make sense to upcast instead of downcast? This upcasts: x = M.matrix([[1, M.nan, 3]]) x matrix([[ 1., nan, 3.]]) But this doesn't: x = M.matrix([[1, 2, 3]]) x[0,1] = M.nan x

Re: [Numpy-discussion] Grief with a complex value

2006-11-09 Thread Stefan van der Walt
On Thu, Nov 09, 2006 at 03:18:57AM -0500, Colin J. Williams wrote: import numpy.core as _n _nt= _n.numerictypes value= '[EMAIL PROTECTED]@[EMAIL PROTECTED]@\x00\x00\x00\x00\x00\x00\x18@' _n.array(value, dtype= _nt.complex128, copy=True) Traceback (most recent call last): File

Re: [Numpy-discussion] matrix multiplication (newbie question)

2006-11-08 Thread Stefan van der Walt
On Wed, Nov 08, 2006 at 05:54:17AM -0800, izak marais wrote: Hi Sorry if this is an obvious question, but what is the easiest way to multiply matrices in numpy? Suppose I want to do A=B*C*D. The ' * ' operator apparently does element wise multiplication, as does the 'multiply' ufunc. All I

Re: [Numpy-discussion] ctypes warning

2006-11-06 Thread Stefan van der Walt
On Mon, Nov 06, 2006 at 02:09:32PM -0600, John Hunter wrote: A simple import of numpy with the latest svn triggers a ctypes warning In [1]: import numpy /usr/lib/python2.4/site-packages/numpy/ctypeslib.py:12: UserWarning: All features of ctypes interface may not work with ctypes 1.0.1

Re: [Numpy-discussion] Style - was Re: numpy.repeat TypeError: array cannot be safely cast to required type

2006-11-06 Thread Stefan van der Walt
On Mon, Nov 06, 2006 at 03:10:20PM -0500, Colin J. Williams wrote: Many thanks. In general, there is sense in the Python dictum about having one way to do things. Although, in this case [length] vs length for one dimension doesn't exercise me greatly. I would be a bit more concerned about

Re: [Numpy-discussion] ix_ problem changing input arrays?

2006-10-23 Thread Stefan van der Walt
On Mon, Oct 23, 2006 at 11:57:57AM -0400, Scott Ransom wrote: I believe that ix_() has recently begun modifying the shapes of its input arrays. For instance: [...] This should be fixed in SVN. Cheers Stéfan - Using

Re: [Numpy-discussion] Release of 1.0 coming

2006-10-23 Thread Stefan van der Walt
On Mon, Oct 23, 2006 at 05:28:05PM -0600, Travis Oliphant wrote: Yes it has. Fixed. I think ctypes 1.0.1 is required for ndpointer to work, so we might consider some kind of version check + warning on import? Not sure about that. It worked for me using ctypes 1.0.0. You have to

Re: [Numpy-discussion] some work on arpack

2006-10-22 Thread Stefan van der Walt
On Sun, Oct 22, 2006 at 09:27:39AM +0900, Bill Baxter wrote: On 10/22/06, Charles R Harris [EMAIL PROTECTED] wrote: On 10/21/06, Bill Baxter [EMAIL PROTECTED] wrote: Here's something I've been wondering: is it ok to port Matlab functions over to python? If so, then it's maybe an

Re: [Numpy-discussion] Numpy-scalars vs Numpy 0-d arrays: copy or not copy?

2006-10-20 Thread Stefan van der Walt
On Fri, Oct 20, 2006 at 11:42:26AM +0200, Sebastien Bardeau wrote: a = numpy.array((1,2,3)) b = a[:2] Here you index by a slice. c = a[2] Whereas here you index by a scalar. So you want to do b = a[[2]] b += 1 or in the general case b = a[slice(2,3)] b += 1 Regards Stéfan

Re: [Numpy-discussion] adding an attribute to an nd-array

2006-10-19 Thread Stefan van der Walt
On Thu, Oct 19, 2006 at 01:59:49PM -0700, Christopher Barker wrote: Travis Oliphant wrote: Actually something as simple as class InfoArray(N.ndarray): pass will allow you to add attributes to InfoArray. Well, sure, but how the heck do you initialize it? Looks like x =

Re: [Numpy-discussion] adding an attribute to an nd-array

2006-10-19 Thread Stefan van der Walt
On Thu, Oct 19, 2006 at 09:45:02AM -0600, Travis Oliphant wrote: Stefan van der Walt wrote: If I understand correctly, the following should work: import numpy as N class InfoArray(N.ndarray): def __new__(info_arr_cls,arr,info={}): info_arr_cls.info = info return

Re: [Numpy-discussion] What does Fortran order mean?

2006-10-17 Thread Stefan van der Walt
On Tue, Oct 17, 2006 at 10:01:51AM -0600, Travis Oliphant wrote: Charles R Harris wrote: Travis, I note that a = arange(6).reshape(2,3,order='F') a array([[0, 1, 2], [3, 4, 5]]) Shouldn't that be 3x2? Or maybe [[0,2,4],[1,3,5]]? Reshape is making a copy, but

[Numpy-discussion] The NumPy Fortran-ordering quiz

2006-10-17 Thread Stefan van der Walt
Hi all, Some of you may have seen the interesting thread on Fortran-ordering earlier. I thought it might be fun to set up a short quiz which tests your knowledge on the topic. If you're up for the challenge, take a look at http://mentat.za.net/numpy/quiz I won't be held liable for any

Re: [Numpy-discussion] The NumPy Fortran-ordering quiz

2006-10-17 Thread Stefan van der Walt
On Wed, Oct 18, 2006 at 10:30:26AM +0900, Bill Baxter wrote: I think the answer to #3 is wrong. From 1.0rc2 I get: array([1,2,3,4,5,6],order='C').reshape((2,3),order='F') array([[1, 2, 3], [4, 5, 6]]) But the quiz wants me to answer something different. This recently changed.

Re: [Numpy-discussion] Should numpy.sqrt(-1) return 1j rather than nan?

2006-10-12 Thread Stefan van der Walt
I've summarised this thread at http://www.scipy.org/NegativeSquareRoot Feel free to make adjustments, in case I missed something. Regards Stefan - Using Tomcat but need to do more? Need to support web services, security?

Re: [Numpy-discussion] Please test the SVN branch

2006-10-12 Thread Stefan van der Walt
On Thu, Oct 12, 2006 at 12:38:51AM -0600, Travis Oliphant wrote: I made some fixes to the asbuffer code which let me feel better about exposing it in NumPy (where it is now named int_asbuffer). This code takes a Python integer and a size and returns a buffer object that points to that

Re: [Numpy-discussion] Should numpy.sqrt(-1) return 1j rather than nan?

2006-10-12 Thread Stefan van der Walt
On Thu, Oct 12, 2006 at 08:58:21AM -0500, Greg Willden wrote: On 10/11/06, Bill Baxter [EMAIL PROTECTED] wrote: On 10/12/06, Greg Willden [EMAIL PROTECTED] wrote: Speed should not take precedence over correctness. Unless your goal is speed. Then speed should take precedence

Re: [Numpy-discussion] Should numpy.sqrt(-1) return 1j rather than?nan?

2006-10-12 Thread Stefan van der Walt
On Thu, Oct 12, 2006 at 10:53:12AM -0400, Alan G Isaac wrote: On Thu, 12 Oct 2006, Stefan van der Walt apparently wrote: I tried to explain the argument at http://www.scipy.org/NegativeSquareRoot Helpful. But you start off by saying: In mathematics, the above assumption

Re: [Numpy-discussion] Should numpy.sqrt(-1) return 1j rather than nan?

2006-10-11 Thread Stefan van der Walt
On Wed, Oct 11, 2006 at 05:21:44PM -0600, Travis Oliphant wrote: Stefan van der Walt wrote: I agree with Fernando on this one. Further, if I understand correctly, changing sqrt and power to give the right answer by default will slow things down somewhat. But is it worth sacrificing

Re: [Numpy-discussion] Should numpy.sqrt(-1) return 1j rather than nan?

2006-10-11 Thread Stefan van der Walt
On Wed, Oct 11, 2006 at 08:24:01PM -0400, A. M. Archibald wrote: What is the desired behaviour of sqrt? [...] Should it return a complex array only when any entry in its input is negative? This will be even *more* surprising when a negative (perhaps even -0) value appears in their matrix

Re: [Numpy-discussion] Manually broadcasting arrays in Python

2006-10-06 Thread Stefan van der Walt
On Wed, Oct 04, 2006 at 01:37:55AM -0400, A. M. Archibald wrote: Would it be useful for me to contribute the tiny script I wrote to trigger it as a regression test? A. M. Archibald from numpy import vectorize, zeros vt = vectorize(lambda *args: args) # Removing either of the following

[Numpy-discussion] return value of negative power

2006-09-28 Thread Stefan van der Walt
Hi all, Currently, the power function returns '0' for negative powers of integers: In [1]: N.power(3,-2) Out[1]: 0 (or, more confusingly) In [1]: N.power(a,b) Out[1]: 0 which is almost certainly not the answer you want. Two possible solutions may be to upcast the input to float before

Re: [Numpy-discussion] putmask/take ?

2006-09-22 Thread Stefan van der Walt
On Thu, Sep 21, 2006 at 08:35:02PM -0400, P GM wrote: Folks, I'm running into the following problem with putmask on take. import numpy x = N.arange(12.) m = [1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1] i = N.nonzero (m)[0] w = N.array([-1, -2, -3, -4.]) x.putmask(w,m) You can also use

Re: [Numpy-discussion] Putmask/take ?

2006-09-22 Thread Stefan van der Walt
On Fri, Sep 22, 2006 at 02:17:57AM -0500, Robert Kern wrote: Stefan van der Walt wrote: Hi P., On Thu, Sep 21, 2006 at 07:40:39PM -0400, PGM wrote: I'm running into the following problem with putmask on take. import numpy x = N.arange(12.) m = [1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0

[Numpy-discussion] unique1d: renaming retindx to return_index

2006-09-18 Thread Stefan van der Walt
Hi, Would anyone object if I changed the signature of unique1d(ar1, retindx=False) to unique1d(ar1, return_index=False)? I find retindx both harder to read and to type than return_index. Thanks. Stéfan - Take Surveys.

Re: [Numpy-discussion] possible bug with numpy.object_

2006-08-30 Thread Stefan van der Walt
On Tue, Aug 29, 2006 at 10:49:58AM -0600, Travis Oliphant wrote: Matt Knox wrote: is the following behaviour expected? or is this a bug with numpy.object_ ? I'm using numpy 1.0b1 print numpy.array([],numpy.float64).size 0 print numpy.array([],numpy.object_).size 1

Re: [Numpy-discussion] fftfreq very slow; rfftfreq incorrect?

2006-08-30 Thread Stefan van der Walt
On Wed, Aug 30, 2006 at 12:04:22PM +0100, Andrew Jaffe wrote: the current implementation of fftfreq (which is meant to return the appropriate frequencies for an FFT) does the following: k = range(0,(n-1)/2+1)+range(-(n/2),0) return array(k,'d')/(n*d) I have tried this with very

Re: [Numpy-discussion] users point of view and ufuncs

2006-08-25 Thread Stefan van der Walt
On Thu, Aug 24, 2006 at 11:10:24PM -0400, Sasha wrote: I would welcome an effort to make the glossary more novice friendly, but not at the expense of oversimplifying things. BTW, do you think Rank ... (2) number of orthogonal dimensions of a matrix is clear? Considering that matrix is

Re: [Numpy-discussion] ctypes: how does load_library work ?

2006-08-18 Thread Stefan van der Walt
On Fri, Aug 18, 2006 at 01:54:44PM +0900, David Cournapeau wrote: import numpy as N from ctypes import cdll, POINTER, c_int, c_uint _hello = cdll.LoadLibrary('libhello.so') _hello.sum.restype= c_int _hello.sum.artype = [POINTER(c_int), c_uint] def sum(data): return

Re: [Numpy-discussion] bugfix-patch for numpy-1.0b2 setup

2006-08-18 Thread Stefan van der Walt
On Fri, Aug 18, 2006 at 04:45:03PM +0200, Stefan van der Walt wrote: Hi Norbert On Fri, Aug 18, 2006 at 03:36:47PM +0200, Norbert Nemec wrote: in numpy-1.0b2 the logic in setup.py is slightly off. The attached patch fixes the issue. Please file a ticket so that we don't lose track

Re: [Numpy-discussion] Pretty printing an array: no ellipses?

2006-07-20 Thread Stefan van der Walt
On Wed, Jul 19, 2006 at 03:06:00PM -0700, Webb Sprague wrote: I am not sure where to look for this, sorry if it is RTFM or JPS (just plain stupid): Is there a way to set a default to print the entire array, rather than an ellipses version of it? If not, why doesn't

Re: [Numpy-discussion] ImportError: No module named numeric

2006-07-12 Thread Stefan van der Walt
Hi Tamaryn On Wed, Jul 12, 2006 at 11:57:48AM +0100, Tamaryn Menneer wrote: Hi I'm running Python 2.4 on Windows XP. I've installed NumPy, and run the simple test of import numeric but I get the error ImportError: No module named numeric in return. The module numeric is located in

Re: [Numpy-discussion] how to use argsort result?

2006-07-11 Thread Stefan van der Walt
On Tue, Jul 11, 2006 at 11:32:48AM +0200, Emanuele Olivetti wrote: Hi, I don't understand how to use argsort results. I have a 2D matrix and I want to sort values in each row and obtain the index array of that sorting. Argsort(1) is what I need, but the problem is how to use its result in

Re: [Numpy-discussion] Call for a vote on .M .A .T .H attributes

2006-07-07 Thread Stefan van der Walt
On Thu, Jul 06, 2006 at 10:26:12PM -0600, Travis Oliphant wrote: 1) .T Have some kind of .T attribute -1, since the expected behaviour of .T is different depending on problem context. a) .T == .swapaxes(-2,-1) The fact that this was proposed just demonstrates the fact. If you have a

Re: [Numpy-discussion] NumPy C-API now has prefixes

2006-07-07 Thread Stefan van der Walt
On Fri, Jul 07, 2006 at 07:06:58PM -0600, Fernando Perez wrote: On 7/7/06, Travis Oliphant [EMAIL PROTECTED] wrote: I just committed a big change to the NumPy SVN (r2773-r2777) which adds the prefix npy_ or NPY_ to all names not otherwise pre-fixed. There is also a noprefix.h header that

Re: [Numpy-discussion] Determining if two arrays share data

2006-07-06 Thread Stefan van der Walt
On Thu, Jul 06, 2006 at 11:39:19AM +0900, Bill Baxter wrote: Often when I'm doing interactive prototyping I find myself wanting to check whether two arrays are sharing a copy of the same data. It seems like there ought to be a concise way to do that, but right now seems like the only way is

Re: [Numpy-discussion] Numexpr does broadcasting.

2006-06-22 Thread Stefan van der Walt
Hi Tim On Wed, Jun 21, 2006 at 12:02:27PM -0700, Tim Hochberg wrote: Numexpr can now handle broadcasting. As an example, check out this implementation of the distance-in-a-bunch-of-dimenstions function that's been going around. This is 80% faster than the most recent one posted on my box

Re: [Numpy-discussion] numpy.test(1,10) results in a segfault

2006-05-31 Thread Stefan van der Walt
I filed this as ticket #135: http://projects.scipy.org/scipy/numpy/ticket/135 Regards Stéfan On Wed, May 31, 2006 at 05:47:25PM +0200, Nils Wagner wrote: test_wrap (numpy.core.tests.test_umath.test_special_methods) ... ok check_types (numpy.core.tests.test_scalarmath.test_types)*** glibc