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 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 > individually to each

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

2011-06-21 Thread gary ruben
Hi Ben, based on this example I suspect the way to do it is with numpy.byteswap() and numpy.tofile() >From > we can do >>> A = np.array([1, 256, 8

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 human-readabl

Re: [Numpy-discussion] genfromtxt converter question

2011-06-17 Thread gary ruben
txt(a, dtype=str, delimiter=18)[:,:-1] b = np.vectorize(lambda x: complex(*eval(x)))(b) print b On Sat, Jun 18, 2011 at 12:31 AM, Bruce Southey wrote: > On 06/17/2011 08:51 AM, Olivier Delalleau wrote: > > 2011/6/17 Bruce Southey >> >> On 06/17/2011 08:22 AM, gary ruben wrote:

Re: [Numpy-discussion] genfromtxt converter question

2011-06-17 Thread gary ruben
ert 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 >> >> I'm trying to read a file co

[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 ref

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 wrote: > Dear all pythoners, > > Does anybody know how I can choose the default display style for the data? > like in the follo

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 wrote

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, 0.00

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]), axis=0)

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 , 0.245658

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 l

Re: [Numpy-discussion] Optimized sum of squares

2009-10-18 Thread Gary Ruben
Hi Gaël, If you've got a 1D array/vector called "a", I think the normal idiom is np.dot(a,a) For the more general case, I think np.tensordot(a, a, axes=something_else) should do it, where you should be able to figure out something_else for your particular case. Gary R. Gael Varoquaux wrote: >

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

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

[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 way

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

2009-04-13 Thread Gary Ruben
My friend has used this successfully: Looks like this will do it too: 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? >

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 was

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 millio

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 t

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. Gary R. Gong, Shawn (Contractor) wrote: > hi list, > > I am trying to find 1-D cubic spline function. But I

Re: [Numpy-discussion] 2D Hamming window

2008-07-27 Thread Gary Ruben
Henrik Ronellenfitsch wrote: > 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 "corre

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 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 mem

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. Ni

Re: [Numpy-discussion] Overloading sqrt(5.5)*myvector

2007-12-26 Thread Gary Ruben
Sorry this isn't an answer, just noise, but for those here who don't know, Bruce is the chief maintainer of the vpython project. I have found vpython aka the visual module to be a highly attractive and useful module for teaching physics. It would be great if someone with Boost experience would

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 ar

Re: [Numpy-discussion] Extracting all the possible combinations of a grid

2007-09-21 Thread Gary Ruben
Gael Varoquaux wrote: > On Fri, Sep 21, 2007 at 02:58:43PM -0600, Charles R Harris wrote: >>I found generators a good approach to this sort of thing: > >>for (i,j,k) in triplets(n) : > > That's what we where doing so far, but in the code itself. The result was > unbearably slow. > I thin

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] Documentation

2007-05-15 Thread Gary Ruben
Hi Charles, In you post, is your numpy/doc reference referring to the file HOWTO_DOCUMENT.txt? I notice that this is not the same as the one here which I think may be the preferred standard. If someone can confirm this, it should probably replace the HOWTO_D

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
Thanks Fernando, Good idea. I'll apply your suggestion. Gary Fernando Perez wrote: > On 1/31/07, Gary Ruben <[EMAIL PROTECTED]> wrote: >> Actually, I just realised; it's not an ipython problem. I think it's a >> matplotlib problem. I'll report it th

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 wro

Re: [Numpy-discussion] Requests for NumPy Ports?

2007-01-31 Thread Gary Ruben
Hi Travis, The vpython project was attempting to migrate to numpy and may have achieved it, but I think there may have been some outstanding questions. I'm not sure of the status, but, since you ask, I'd like to see vpython converted. Gary R. Travis Oliphant wrote: > I'm trying to help out th

Re: [Numpy-discussion] Cutting 1.0.2 release

2007-01-31 Thread Gary Ruben
were the core numpy versions. Maybe this has been changed in ipython 0.7.3. Gary R. Alan G Isaac wrote: > On Tue, 30 Jan 2007, Gary Ruben apparently wrote: >> One question, which may be an issue: Should ones, zeros >> and empty be generating arrays of floats by default now? &

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

Re: [Numpy-discussion] ScientificPython with NumPy

2006-11-24 Thread Gary Ruben
> Hi, > Just out of curiosity: Can I ask what is special about a > Geometry.Vector ? What is the difference to a normal numpy array ? At the time I wrote my code, it was just a convenient 3-vector class. Most of the functionality is now implemented in numpy so if I was to rewrite my code, I'd j

Re: [Numpy-discussion] ScientificPython with NumPy

2006-11-24 Thread Gary Ruben
Hi Konrad, I can report that 2.7.1 installs OK on WinXP with the most recent Enthought Python. I used mingw, so replaced the build instruction with python setup.py build --numpy --compiler=mingw32 All I tried was the Geometry.Vector class which my older code uses heavily - this behaves well. rega