Re: [Numpy-discussion] Matrices and arrays of vectors

2012-02-24 Thread gary ruben
I haven't checked correctness, but how about np.tensordot(rotation, data, axes=1) Gary R On 24 February 2012 23:11, Bob Dowling rjd4+nu...@cam.ac.uk wrote: Conceptually, I have a 2-d grid of 2-d vectors.  I am representing this as an ndarray of shape (2,M,N).  I want to apply a 2x2 matrix

Re: [Numpy-discussion] Controlling endianness of ndarray.tofile()

2011-06-21 Thread gary ruben
Hi Ben, based on this example https://bitbucket.org/lannybroo/numpyio/src/a6191c989804/numpyIO.py I suspect the way to do it is with numpy.byteswap() and numpy.tofile() From http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.byteswap.html we can do A = np.array([1, 256, 8755],

Re: [Numpy-discussion] genfromtxt converter question

2011-06-17 Thread gary ruben
convert only the second column, because your converters dictionary contains a single key (1). If you have it contain keys from 0 to 3 associated to the same function, it should work. -=- Olivier 2011/6/17 gary ruben gru...@bigpond.net.au I'm trying to read a file containing data formatted

Re: [Numpy-discussion] genfromtxt converter question

2011-06-17 Thread gary ruben
)[:,:-1] b = np.vectorize(lambda x: complex(*eval(x)))(b) print b On Sat, Jun 18, 2011 at 12:31 AM, Bruce Southey bsout...@gmail.com wrote: On 06/17/2011 08:51 AM, Olivier Delalleau wrote: 2011/6/17 Bruce Southey bsout...@gmail.com On 06/17/2011 08:22 AM, gary ruben wrote: Thanks Olivier, Your

Re: [Numpy-discussion] genfromtxt converter question

2011-06-17 Thread gary ruben
Thanks guys - I'm happy with the solution for now. FYI, Derek's suggestion doesn't work in numpy 1.5.1 either. For any developers following this thread, I think this might be a nice use case for genfromtxt to handle in future. As a corollary of this problem, I wonder whether there's a

[Numpy-discussion] genfromtxt converter question

2011-06-16 Thread gary ruben
I'm trying to read a file containing data formatted as in the following example using genfromtxt and I'm doing something wrong. It almost works. Can someone point out my error, or suggest a simpler solution to the ugly converter function? I thought I'd leave in the commented-out line for future

Re: [Numpy-discussion] ndarray display in ipython

2011-06-12 Thread gary ruben
You control this with numpy.set_printoptions: http://docs.scipy.org/doc/numpy/reference/generated/numpy.set_printoptions.html On Sun, Jun 12, 2011 at 10:10 PM, Chao YUE chaoyue...@gmail.com wrote: Dear all pythoners, Does anybody know how I can choose the default display style for the data?

Re: [Numpy-discussion] k maximal elements

2011-06-06 Thread gary ruben
I learn a lot by watching the numpy and scipy lists (today Olivier taught me about heapq :), but he may not have noticed that Python 2.4 added an nsmallest method) import heapq q = list(x) heapq.heapify(q) k_smallest = heapq.nsmallest(k,q) On Mon, Jun 6, 2011 at 10:52 PM, Olivier Delalleau

Re: [Numpy-discussion] numpy input with genfromttxt()

2011-06-03 Thread gary ruben
I think the easiest is to use an intermediate string. If your file is test.txt, In [22]: a = file('test.txt').read().replace(',','.') In [23]: import StringIO In [24]: b=genfromtxt(StringIO.StringIO(a)) In [25]: b Out[25]: array([[ 0.e+00, 1.2210e-03, 1.2210e-03,

Re: [Numpy-discussion] Question regarding concatenate/vstack.

2011-03-30 Thread gary ruben
You're right, they are not equivalent. vstack will happily create an array of higher rank than the parts it is stacking, whereas concatenate requires the arrays it is working with to already be at least 2d, so the equivalent is np.concatenate((np.arange(5.)[newaxis],np.arange(5.)[newaxis]),

Re: [Numpy-discussion] Norm of array of vectors

2011-03-17 Thread gary ruben
How about argmin(add.reduce((a*a),axis=1)) In [5]: a Out[5]: array([[ 0.24202827, 0.01269182, 0.95162307], [ 0.02979253, 0.454 , 0.49650111], [ 0.52626565, 0.08363861, 0.56444878], [ 0.89639659, 0.54259354, 0.29245881], [ 0.75301013, 0.6248646 ,

Re: [Numpy-discussion] indices of values contained in a list

2009-12-12 Thread Gary Ruben
np.setmember1d(a,b) does the same as your reduce(np.logical_or, [a == i for i in b]) but it's actually slower on my machine! Gary R. Ernest Adrogué wrote: Hi, Suppose I have a flat array, and I want to know the indices corresponding to values contained in a list of arbitrary lenght.

Re: [Numpy-discussion] Optimized sum of squares

2009-10-22 Thread Gary Ruben
josef.p...@gmail.com wrote: Is it really possible to get the same as np.sum(a*a, axis) with tensordot if a.ndim=2 ? Any way I try the something_else, I get extra terms as in np.dot(a.T, a) Just to answer this question, np.dot(a,a) is equivalent to np.tensordot(a,a, axis=(0,0)) but the

Re: [Numpy-discussion] Mirror/flip numpy array?

2009-07-17 Thread Gary Ruben
In [1]: a=array([1,2,3]) In [2]: a[::-1] Out[2]: array([3, 2, 1]) Johannes Bauer wrote: Hello list, I have a really simple newbie question: How can I mirror/flip a numpy.ndarray? I.e. mirror switches the colums (leftmost becomes rightmost and so on), flip changes the rows (top becomes

[Numpy-discussion] help with applying a transform

2009-04-18 Thread Gary Ruben
I'm trying to work out how to apply a 2x2 transform matrix to a spinor, e.g. [psi1'] [a b][psi1] [ ] = [][] [psi2'] [c d][psi2] where [[a,b],[c,d]] is a transform matrix and psi1 and psi2 are i x j x k complex arrays representing complex scalar field data. I worked that one

Re: [Numpy-discussion] help with applying a transform

2009-04-18 Thread Gary Ruben
I think I've answered my own question - I remembered tensordot, and the following seems to work: def transform(tx_matrix, psi1, psi2): psi = np.tensordot(tx_matrix, np.concatenate((psi1[newaxis],psi2[newaxis])),axes=1)) return psi[0], psi[1] sorry for the noise, Gary Gary

Re: [Numpy-discussion] [OT] read data from pdf

2009-04-13 Thread Gary Ruben
My friend has used this successfully: http://www.datathief.org/ Looks like this will do it too: http://www.datamaster2003.com/ Gary R. João Luís Silva wrote: Neal Becker wrote: Anyone know of software that can assist with reading data points from a pdf version of a 2-d line graph? There

Re: [Numpy-discussion] example reading binary Fortran file

2009-01-30 Thread Gary Ruben
The only time I've done this, I used numpy.fromfile exactly as follows. The file had a header followed by a number of records (one float followed by 128 complex numbers), requiring separate calls of numpy.fromfile to read each part. The only strange part about this was that the Fortran code

Re: [Numpy-discussion] numpy fileIO

2008-10-16 Thread Gary Ruben
Prashant Saxena wrote: I am seeing all the OSS for this purpose but I would stick to use pure python and the scene graph I am developing for the application. I already did some test using pyOpenGL/python/wx.GLcanvas and a large data set of roughly 4000+ objects consisting nearly 1 million

Re: [Numpy-discussion] normalizing a vector so it has magnitude 1

2008-08-27 Thread Gary Ruben
I don't know what you mean by a 1D vector, but for a 3-vector, you can do this (also works for N-dimensions) In [1]: a=r_[1.,2.,3.] In [2]: a Out[2]: array([ 1., 2., 3.]) In [3]: b=a/norm(a) In [4]: b Out[4]: array([ 0.26726124, 0.53452248, 0.80178373]) Gary R bit of a newb question, is

Re: [Numpy-discussion] cubic spline function in numarray or numpy

2008-08-06 Thread Gary Ruben
You're best off using scipy. Just Google search for scipy spline: e.g. http://www.scipy.org/Cookbook/Interpolation http://xinqingpeng.blogspot.com/2007/07/scipy-spline-example.html Gary R. Gong, Shawn (Contractor) wrote: hi list, I am trying to find 1-D cubic spline function. But I am not

Re: [Numpy-discussion] 2D Hamming window

2008-07-27 Thread Gary Ruben
Henrik Ronellenfitsch wrote: snip Thanks very much for your solution, this is exactly what I needed! If I'm not mistaken, though, you can achieve the same result with h = hamming(n) ham2d = sqrt(outer(h,h)) which is a bit more compact. Regards, Henrik Yes, that's nicer. regards,

Re: [Numpy-discussion] 2D Hamming window

2008-07-26 Thread Gary Ruben
Henrik Ronellenfitsch wrote: Hello! I'm looking for a 2D hamming window function. As far as I can see, numpy only supports 1D windows and googling didn't show a simple way of extending it in two dimensions. Thanks for your help, Henrik Hi Henrik, I haven't looked at the correct way to

Re: [Numpy-discussion] Detecting phase windings

2008-07-09 Thread Gary Ruben
I had a chance to look at Anne's suggestion from this thread http://www.mail-archive.com/numpy-discussion@scipy.org/msg10091.html and I thought I should post my phase winding finder solution, which is slightly modified from her idea. Thanks Anne. This is a vast improvement over my original slow

Re: [Numpy-discussion] Detecting phase windings

2008-06-20 Thread Gary Ruben
Hi Anne, Thanks for the approach ideas - I'll take a look at this soon to try to understand it. Currently I'm visiting a LabView-based lab who already have something that works, and works fast, so I'm being encouraged to use LabView, but I'd like to show them more of the joys of Python. The

Re: [Numpy-discussion] Win32 installer: please test it

2008-04-14 Thread Gary Ruben
Tested fine on my old Classic Athlon 500 (no SSE) under Win98. It correctly reported installing the non-SSE version when I clicked on the details button on the last page of the install wizard. Whereas previously numpy.test() would bring up an illegal operation dialog box, now all tests pass.

Re: [Numpy-discussion] Convert array type

2007-10-06 Thread Gary Ruben
Try using astype. This works: values = array(wavearray.split()).astype(float) Gary R. Adam Mercer wrote: values = array(wavearray.split()) where wavearray is a string containing a series of floats separated by white space, it appears that the individual elements of the values array are

Re: [Numpy-discussion] Working with lists

2007-08-09 Thread Gary Ruben
FWIW, The list comprehension is faster than using map() In [7]: %timeit map(lambda x:x[0],bounds) 1 loops, best of 3: 49.6 -¦s per loop In [8]: %timeit [x[0] for x in bounds] 1 loops, best of 3: 20.8 -¦s per loop Gary R. Keith Goodman wrote: On 8/9/07, Nils Wagner [EMAIL PROTECTED]

Re: [Numpy-discussion] numpy version of Interactive Data Analysis tutorial available

2007-05-11 Thread Gary Ruben
This is great Perry, I think this will help to convince our department's astronomer(s) to learn and maybe use Python for teaching. By the way, if you do a global search for numarray in your document, you'll pick up a few pieces of unchanged text and code. Gary R. Perry Greenfield wrote: I

Re: [Numpy-discussion] Cutting 1.0.2 release

2007-01-31 Thread Gary Ruben
Actually, I just realised; it's not an ipython problem. I think it's a matplotlib problem. I'll report it there. Gary R. Steve Lianoglou wrote: Thanks Alan Chris, My apologies. I was trying ones(), zeros() and empty() in ipython 0.7.2 with the -pylab option and getting the wrong

Re: [Numpy-discussion] Cutting 1.0.2 release

2007-01-30 Thread Gary Ruben
One question, which may be an issue: Should ones, zeros and empty be generating arrays of floats by default now? Gary R. Travis Oliphant wrote: I think it's time for the 1.0.2 release of NumPy. What outstanding issues need to be resolved before we do it? Hopefully, we can do it by the