Re: [Numpy-discussion] dates, np.where finding months

2010-01-20 Thread John [H2O]
Keith Goodman wrote: > > > > Or maybe this is cleaner: > >>> [date.month==1 for date in A[:,0]] >[True, True, False, True] > > which can be used like this: > >>> idx = np.array([date.month==1 for date in A[:,0]]) >>> A[idx,:] > > array([[2010-01-01, 1], >[2010-01-02, 2], >

[Numpy-discussion] dates, np.where finding months

2010-01-20 Thread John [H2O]
I have an array with the leading column a series of datetime objects. It covers several years. What is the most efficient way to pull out all the 'January' dates? Right now I do this: A = array with column 0 datetime objects January = [i for i in A if i[0].month ==1 ] It works, but I would ra

Re: [Numpy-discussion] more recfunctions, structured array help

2009-12-08 Thread John [H2O]
Pierre GM-2 wrote: > > On Dec 8, 2009, at 7:27 PM, John [H2O] wrote: >> Maybe I should add, I'm looking at this thread: >> http://old.nabble.com/masked-record-arrays-td26237612.html >> >> And, I guess I'm in the same situation as the OP there. It's

Re: [Numpy-discussion] more recfunctions, structured array help

2009-12-08 Thread John [H2O]
Maybe I should add, I'm looking at this thread: http://old.nabble.com/masked-record-arrays-td26237612.html And, I guess I'm in the same situation as the OP there. It's not clear to me, but as best I can tell I am working with structured arrays (that's from np.rec.fromrecords creates, no?). Anywa

Re: [Numpy-discussion] more recfunctions, structured array help

2009-12-08 Thread John [H2O]
Pierre GM-2 wrote: > > > Did you check scikits.timeseries ? Might be a solution if you have data > indexed in time > > >> np.rec.fromrecords(codata_masked,names='datetime,lon,lat,elv,co') >>return codata, codata_masked > > OK, I gonna have to guess again: > codata is a regular ndarray, n

Re: [Numpy-discussion] more recfunctions, structured array help

2009-12-08 Thread John [H2O]
Pierre GM-2 wrote: > > > > masked_where is a function that requires 2 arguments. > If you try to mask a whole record, you can try something like x = ma.array([('a',1),('b',2)],dtype=[('','|S1'),('',float)]) x[x['f0']=='a'] = ma.masked > For an individual field, try something like >>>

Re: [Numpy-discussion] more recfunctions, structured array help

2009-12-08 Thread John [H2O]
This is what I get: In [74]: type(cd) Out[74]: In [75]: type(cd.co) Out[75]: In [76]: cd[cd['co']==-.] = np.ma.masked --- ValueErrorTraceback (most recent call last) /home/jfb/Research

[Numpy-discussion] more recfunctions, structured array help

2009-12-08 Thread John [H2O]
I see record arrays don't have a masked_where method. How can I achieve the following for a record array: cd.masked_where(cd.co == -.) Or something like this. Thanks! -- View this message in context: http://old.nabble.com/more-recfunctions%2C-structured-array-help-tp26700380p26700380.htm

[Numpy-discussion] re cfunctions help with concatenating (vstack, hstack, etc.)

2009-12-07 Thread John [H2O]
Hello (Pierre?), I'm trying to work more with structured arrays, which at times seems great, and at others (due to my lack of familiarity) very frustrating. Anyway, right now I'm writing a bit of code to read a series of files with x,y,z data. I'm creating record arrays for each file a read. Onc

[Numpy-discussion] exec: bad practice?

2009-09-15 Thread John [H2O]
Hello, I have a bit of code where I create arrays with meaningful names via: meat = ['beef','lamb','pork'] cut = ['ribs','cutlets'] for m in meat: for c in cut: exec("consumed_%s_%s = np.zeros((numxgrid,numygrid,nummeasured))" % (m,c)) Is this 'pythonic'? Or is it bad practice (and

[Numpy-discussion] iteration slowing, no increase in memory

2009-09-10 Thread John [H2O]
Hello, I have a routine that is iterating through a series of directories, loading files, plotting, then moving on... It runs very well for the first few iterations, but then slows tremendously - there is nothing significantly different about the files or directory in which it slows. I've monito

[Numpy-discussion] re loading f2py modules in ipython

2009-09-09 Thread John [H2O]
Hello, I've started to rely more and more on f2py to create simple modules utilizing Fortran for efficiency. This is a great tool to have within Python! A problem, however, is that unlike python modules, the reload() function does not seem to update the f2py modules within ipython (which I use e

Re: [Numpy-discussion] Masking an array with another array

2009-08-12 Thread John [H2O]
I suspect I am trying to do something similar... I would like to create a mask where I have data. In essence, I need to return True where x,y is equal to lon,lat I suppose a setmember solution may somehow be more elegant, but this is what I've worked up for now... suggestions? def genData

[Numpy-discussion] indexing recarrays

2009-07-20 Thread John [H2O]
I have a file containing mixed data types: strings, floats, datetime output(i.e. strings), and ints. Something like: #ID, name, date, value 1,sample,2008-07-10 12:34:20,344.56 Presuming I get them nicely into a recarray (see my other http://www.nabble.com/recarray-and-datetime-objects-td245683

[Numpy-discussion] re carray and datetime objects

2009-07-20 Thread John [H2O]
Hello, I have a file containing mixed data types: strings, floats, datetime output(i.e. strings), and ints. Something like: #ID, name, date, value 1,sample,2008-07-10 12:34:20,344.56 And so forth. It seems using recarrays is efficient and a prefered habit to get into wrg to numpy, so I am tryin

[Numpy-discussion] np.concatenate and np.column_stack shouldn't they be the same?

2009-07-10 Thread John [H2O]
Can someone explain: x = np.arange(20) y = np.arange(20) z = np.vstack((x,y)).T is equal to: z = np.column_stack((x,y)) but this does not do the same: z = np.concatenate((x,y),axis=0) # or with axis=1 Seems I should be able to use concatenate to make a column stack?? Thanks! -- View this

Re: [Numpy-discussion] Help with np.where and datetime functions

2009-07-08 Thread John [H2O]
Also, could someone please explain why: Tsub = T[ (T[:,0]>t1) & (T[:,0]http://www.nabble.com/Help-with-np.where-and-datetime-functions-tp24389447p24401687.html Sent from the Numpy-discussion mailing list archive at Nabble.com. ___ NumPy-Discussion mail

Re: [Numpy-discussion] Help with np.where and datetime functions

2009-07-08 Thread John [H2O]
nhmc wrote: > > > > Also, if you don't need the indices, you can just use the conditional > expression as a boolean mask: > condition = (t1 < Y[:,0]) & (Y[:,0] < t2) Y[:,0][condition] > > Neil > 'condition' is not an index array? Wouldn't it just be the indices as well? Would i

Re: [Numpy-discussion] Help with np.where and datetime functions

2009-07-08 Thread John [H2O]
Pierre GM-2 wrote: > > > > Would you like to give the scikits.timeseries package a try ? It's > available at pytseries.sourceforge.net. > Calculatng the hourly average should be straightforward. > I would, in fact I have been investigating it, but I didn't have numpy1.3 up and running unti

[Numpy-discussion] Help with np.where and datetime functions

2009-07-08 Thread John [H2O]
Hello, I have several issues which require me to iterate through a fairly large array (30+ records). The first case is calculating and hourly average from non-regularly sampled data. The second is screening one array, based on data in the second array. The functions are defined below, but in

Re: [Numpy-discussion] upgrading numpy to 1.3 on ubuntu

2009-07-06 Thread John [H2O]
/usr/local/lib/python2.6/dist-packages with whatever directory > you installed your numpy 1.3 in. This path will be imported before any of > the other standard directories. > > > > On Mon, Jul 6, 2009 at 5:08 PM, John [H2O] wrote: > >> >> Hello, >> >> I

[Numpy-discussion] upgrading numpy to 1.3 on ubuntu

2009-07-06 Thread John [H2O]
Hello, I run Ubuntu 9.04 which has python-numpy 1.2 installed through apt-get. I would like to upgrade to 1.3 in order to be able to use the scikits.timeseries package. However, I cannot seem to do it using apt-get/aptitude/synaptic or at least not that I've discovered. Currently: python -c "im

Re: [Numpy-discussion] probably simple, reverse a reshape...

2009-02-23 Thread John [H2O]
John [H2O] wrote: > > Hello, this is probably one of those questions that is going to seem > simple after reading responses... > and a few more minutes of thinking: def row2shape(row,a): """ to get indices a 2d array row# to the 3d array from which i

[Numpy-discussion] probably simple, reverse a reshape...

2009-02-23 Thread John [H2O]
Hello, this is probably one of those questions that is going to seem simple after reading responses... I'm trying to get the original array indices out of a row number from a reshaped array... shouldn't this be possible somehow? import numpy as np a = np.ones((3,5,10)) #for testing, I've done t

[Numpy-discussion] efficient function calculation between two matrices

2009-02-17 Thread John [H2O]
hello, I am trying to calculate the results of a function between two matrices: >>> F.shape (170, 2) >>> T.shape (170, 481, 2) Where F contains lat/lon pairs and T contains 481 lat/lon pairs for 170 trajectories of length 481 I want a new array of shape (170,481) containing the results of my