Re: numpy arrays

2016-04-11 Thread Heli
As you said, this did the trick. sortedVal=np.array(val[ind]).reshape((xcoord.size,ycoord.size,zcoord.size)) Only val[ind] instead of val[ind,:] as val is 1D. Thanks Oscar, -- https://mail.python.org/mailman/listinfo/python-list

Re: numpy arrays

2016-04-11 Thread Heli
Thanks Oscar, In my case this did the trick. sortedVal=np.array(val[ind]).reshape((xcoord.size,ycoord.size,zcoord.size)) -- https://mail.python.org/mailman/listinfo/python-list

Re: numpy arrays

2016-04-07 Thread Oscar Benjamin
On 7 April 2016 at 15:31, Heli wrote: > > Thanks a lot Oscar, > > The lexsort you suggested was the way to go. Glad to hear it. > import h5py > import numpy as np > f=np.loadtxt(inputFile,delimiter=None) > xcoord=np.sort(np.unique(f[:,0])) > ycoord=np.sort(np.unique(f[:,1])) > zcoord=np.sort(np.

Re: numpy arrays

2016-04-07 Thread Heli
Thanks a lot Oscar, The lexsort you suggested was the way to go. import h5py import numpy as np f=np.loadtxt(inputFile,delimiter=None) xcoord=np.sort(np.unique(f[:,0])) ycoord=np.sort(np.unique(f[:,1])) zcoord=np.sort(np.unique(f[:,2])) x=f[:,0] y=f[:,1] z=f[:,2] val=f[:,3] ind = np.lexsort(

Re: numpy arrays

2016-04-07 Thread Oscar Benjamin
On 6 April 2016 at 17:26, Heli wrote: > > Thanks for your replies. I have a question in regard with my previous > question. I have a file that contains x,y,z and a value for that coordinate > on each line. Here I am giving an example of the file using a numpy array > called f. > > f=np.array([[

Re: numpy arrays

2016-04-06 Thread Heli
Thanks for your replies. I have a question in regard with my previous question. I have a file that contains x,y,z and a value for that coordinate on each line. Here I am giving an example of the file using a numpy array called f. f=np.array([[1,1,1,1], [1,1,2,2], [1,1,3

Re: numpy arrays

2016-03-23 Thread Nobody
> What you want is called *transposing* the array: > > http://docs.scipy.org/doc/numpy/reference/generated/numpy.transpose.html > > That should be a sufficiently fast operation. Transposing itself is fast, as it just swaps the strides and dimensions without touching the data (i.e. it returns a n

Re: numpy arrays

2016-03-23 Thread Simon Ward
On 23 March 2016 10:06:56 GMT+00:00, Heli wrote: >Hi, > >I have a 2D numpy array like this: > >[[1,2,3,4], > [1,2,3,4], > [1,2,3,4] > [1,2,3,4]] > >Is there any fast way to convert this array to > >[[1,1,1,1], > [2,2,2,2] > [3,3,3,3] > [4,4,4,4]] Use the transpose() method: http://docs.scipy

Re: numpy arrays

2016-03-23 Thread Heli
On Wednesday, March 23, 2016 at 11:07:27 AM UTC+1, Heli wrote: > Hi, > > I have a 2D numpy array like this: > > [[1,2,3,4], > [1,2,3,4], > [1,2,3,4] > [1,2,3,4]] > > Is there any fast way to convert this array to > > [[1,1,1,1], > [2,2,2,2] > [3,3,3,3] > [4,4,4,4]] > > In general I wo

Re: numpy arrays

2016-03-23 Thread Chris Angelico
On Wed, Mar 23, 2016 at 9:06 PM, Heli wrote: > I have a 2D numpy array like this: > > [[1,2,3,4], > [1,2,3,4], > [1,2,3,4] > [1,2,3,4]] > > Is there any fast way to convert this array to > > [[1,1,1,1], > [2,2,2,2] > [3,3,3,3] > [4,4,4,4]] What you want is called *transposing* the array: h

Re: numpy arrays

2016-03-23 Thread Manolo Martínez
On 03/23/16 at 03:06am, Heli wrote: > I have a 2D numpy array like this: > > [[1,2,3,4], > [1,2,3,4], > [1,2,3,4] > [1,2,3,4]] > > Is there any fast way to convert this array to > > [[1,1,1,1], > [2,2,2,2] > [3,3,3,3] > [4,4,4,4]] You don't mean just transposing your original array, as

Re: numpy arrays

2016-03-23 Thread Steven D'Aprano
On Wed, 23 Mar 2016 09:06 pm, Heli wrote: > Hi, > > I have a 2D numpy array like this: > > [[1,2,3,4], > [1,2,3,4], > [1,2,3,4] > [1,2,3,4]] > > Is there any fast way to convert this array to > > [[1,1,1,1], > [2,2,2,2] > [3,3,3,3] > [4,4,4,4]] Mathematically, this is called the "tran

Re: numpy arrays to python compatible arrays

2010-06-12 Thread Javier Montoya
On Jun 11, 12:29 am, Martin wrote: > On Jun 10, 9:02 pm, Philip Semanchuk wrote: > > > > > On Jun 10, 2010, at 9:58 AM,JavierMontoyawrote: > > > > Dear all, > > > > I'm new to python and have been working with the numpy package. I have > > > some numpy float arrays (obtained from np.fromfile and

Re: numpy arrays to python compatible arrays

2010-06-10 Thread Martin
On Jun 10, 9:02 pm, Philip Semanchuk wrote: > On Jun 10, 2010, at 9:58 AM, Javier Montoya wrote: > > > Dear all, > > > I'm new to python and have been working with the numpy package. I have > > some numpy float arrays (obtained from np.fromfile and np.cov > > functions) and would like to convert t

Re: numpy arrays to python compatible arrays

2010-06-10 Thread Philip Semanchuk
On Jun 10, 2010, at 9:58 AM, Javier Montoya wrote: Dear all, I'm new to python and have been working with the numpy package. I have some numpy float arrays (obtained from np.fromfile and np.cov functions) and would like to convert them to simple python arrays. I was wondering which is the best

Re: NumPy arrays that use memory allocated from other libraries or tools

2008-09-11 Thread Travis Oliphant
sturlamolden wrote: On Sep 10, 6:39 am, Travis Oliphant <[EMAIL PROTECTED]> wrote: I wanted to point anybody interested to a blog post that describes a useful pattern for having a NumPy array that points to the memory created by a different memory manager than the standard one used by NumPy.

Re: NumPy arrays that use memory allocated from other libraries or tools

2008-09-10 Thread sturlamolden
On Sep 10, 6:39 am, Travis Oliphant <[EMAIL PROTECTED]> wrote: > I wanted to point anybody interested to a blog post that describes a > useful pattern for having a NumPy array that points to the memory > created by a different memory manager than the standard one used by > NumPy. Here is somethi