Re: [Numpy-discussion] subset of array - statistics
I am new to the world of Python and numpy Welcome. I have successfully imported the data into lists and then created a single array from the lists. I think putting each quantity in a 1D array is more practical in this case. I can get the rainfall total over the entire period using: But what i would like to do is get an average rainfall for each month and also the ability to get rainfall totals for any month and Year Assuming that yr, mth and rain are 1D arrays, you may try something along [[average(rain[(yr == y) & (mth == m)]) for m in unique(mth[yr==y])] for y in unique(yr)] which gives you the monthly average rainfalls stored in lists, one for each year. The rain data cannot be reshaped in a 3D numpy array, because not all months have the same number of days, and not all years have the same number of months. If they could, numpy would allow you to do something like: average(rain.reshape(Nyear, Nmonth, Nday), axis =-1) to get the same result. J. Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] fromfunction() bug?
On Thu, Mar 13, 2008 at 06:18:30PM -0400, Alan G Isaac wrote: > This is how I would hope ``fromfunction`` would work > and it matches the docs. (See below.) You can fix > the example ... Interesting, i thought the output in the Example List page is auto-generated... ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] fromfunction() bug?
This is how I would hope ``fromfunction`` would work and it matches the docs. (See below.) You can fix the example ... Cheers, Alan Isaac >>> help(N.fromfunction) Help on function fromfunction in module numpy.core.numeric: fromfunction(function, shape, **kwargs) Returns an array constructed by calling a function on a tuple of number grids. The function should accept as many arguments as the length of shape and work on array inputs. The shape argument is a sequence of numbers indicating the length of the desired output for each axis. The function can also accept keyword arguments (except dtype), which will be passed through fromfunction to the function itself. The dtype argument (default float) determines the data-type of the index grid passed to the function. ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] fromfunction() bug?
Hi, According to the fromfunction() example: http://www.scipy.org/Numpy_Example_List_With_Doc#head-597e63df5a6d490abd474ffd84d0419468c8329a fromfunction() should return an array of integers. But when i run the example, i obtain an array of floats: >>> from numpy import * >>> def f(i,j): ... return i**2 + j**2 ... >>> fromfunction(f, (3,3)) array([[ 0., 1., 4.], [ 1., 2., 5.], [ 4., 5., 8.]]) I am on version 1.0.4, same as the examples. Is this a bug? ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] fromiter + dtype='S' -> Python crash
On Thu, 13 Mar 2008, Alexander Michael apparently wrote: > I wasn't sure if there was a magic numpy > method to do the loop quickly (as the destination array is created > beforehand) without creating a temporary Python list, but I guess not. > The generator/list-comprehension is likely better than my prototype. Looks like I misunderstood your question: you want an **array** of strings? In principle you should be able to use ``fromiter``, I believe, but it does not work. BUG? (Crasher.) Cheers, Alan Isaac >>> import numpy as N >>> x = [1,2,3] >>> fmt="%03d" >>> N.array([fmt%xi for xi in x],dtype='S') array(['001', '002', '003'], dtype='|S3') >>> N.fromiter([xi for xi in x],dtype='float') array([ 1., 2., 3.]) >>> N.fromiter([xi for xi in x],dtype='S') Python crashes. ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Help needed with numpy 10.5 release blockers
I appologize that the Mac OSX buildbot has been so flakey. For some reason it stops being able to resolve scipy.org on a regular basis (though other processes on the same machine don't seem to have trouble). Restarting the slave fixes the issue. Anyways, if anyone is testing an OS X issue and the svn update fails, let me know. Barry On Thu, Mar 13, 2008 at 2:38 AM, Jarrod Millman <[EMAIL PROTECTED]> wrote: > On Wed, Mar 12, 2008 at 10:43 PM, Jarrod Millman <[EMAIL PROTECTED]> wrote: > > Stefan and I also triaged the remaining tickets--closing several and > > turning others in to release blockers: > > > http://scipy.org/scipy/numpy/query?status=new&severity=blocker&milestone=1.0.5&order=priority > > > > I think that it is especially important that we spend some time trying > > to make the 1.0.5 release rock solid. There are several important > > changes in the trunk so I really hope we can get these tickets > > resolved ASAP. I need everyone's help getting this release out. If > > you can help work on any of the open release blockers, please try to > > close them over the weekend. If you have any ideas about the tickets > > but aren't exactly sure how to resolve them please post a message to > > the list or add a comment to the ticket. > > Hello, > > I just noticed that David Cournapeau fixed one of the blockers moments > after I sent out my email asking for help: > http://projects.scipy.org/scipy/numpy/ticket/688 > > Thanks David! > > So we are down to 12 tickets blocking the release. Some of the > tickets are just missing tests, so they should be fairly easy to > implement--for anyone who wants to help get this release out ASAP. > > Cheers, > > -- > > > Jarrod Millman > Computational Infrastructure for Research Labs > 10 Giannini Hall, UC Berkeley > phone: 510.643.4014 > http://cirl.berkeley.edu/ > ___ > Numpy-discussion mailing list > Numpy-discussion@scipy.org > http://projects.scipy.org/mailman/listinfo/numpy-discussion > ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] subset of array - statistics
Hello, I am new to the world of Python and numpy but am very excited by what I have seen so far. I have been playing around with some rainfall data. The data is daily rainfall for a period, say 30 years in the form: Year Month JulianDay Rain (mm) 1970 1 1 0.0 1970 1 2 0.5 . 2008 3 65 2.5 I have successfully imported the data into lists and then created a single array from the lists. I can get the rainfall total over the entire period using: raindata = numpy.array([yr,mth,jd,rain_mm],dtype=float) print data[3,:].sum(axis=0) or raindata= numpy.rec.fromarrays ([yr,mth,jd,rain_mm],names='year,month,julian,rain_mm') print raindata.rain_mm.sum(axis=0) But what i would like to do is get an average rainfall for each month and also the ability to get rainfall totals for any month and Year I thought it would be straight forward but have not gotten my head around it yet. Thanks for your help and thakns to the people eho have develoepd and maintain numpy & python ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Transforming an array of numbers to an array of formatted strings
On Thu, Mar 13, 2008 at 9:49 AM, Alan G Isaac <[EMAIL PROTECTED]> wrote: > And for 1d array ``x`` you can always do:: > >strdata = list( fmt%xi for xi in x) > > Nice because the counter name does not "bleed" into your program. On Thu, Mar 13, 2008 at 3:07 PM, David Huard <[EMAIL PROTECTED]> wrote: > ['S%03d'%i for i in int_data] Thanks for the suggestions! I wasn't sure if there was a magic numpy method to do the loop quickly (as the destination array is created beforehand) without creating a temporary Python list, but I guess not. The generator/list-comprehension is likely better than my prototype. Regards, Alex ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Transforming an array of numbers to an array of formatted strings
> 2008/3/13, Alan G Isaac <[EMAIL PROTECTED]>: >> strdata = list( fmt%xi for xi in x) >> Nice because the counter name does not "bleed" into your program. On Thu, 13 Mar 2008, David Huard apparently wrote: > ['S%03d'%i for i in int_data] The difference is that the counter "bleeds" from the list comprehension. I find that obnoxious. Cheers, Alan Isaac ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Transforming an array of numbers to an array of formatted strings
['S%03d'%i for i in int_data] David 2008/3/13, Alan G Isaac <[EMAIL PROTECTED]>: > > On Thu, 13 Mar 2008, Alexander Michael apparently wrote: > > I want to format an array of numbers as strings. > > > To what end? > Note that tofile has a format option. > And for 1d array ``x`` you can always do:: > > strdata = list( fmt%xi for xi in x) > > Nice because the counter name does not "bleed" into your program. > > Cheers, > Alan Isaac > > > > ___ > Numpy-discussion mailing list > Numpy-discussion@scipy.org > http://projects.scipy.org/mailman/listinfo/numpy-discussion > ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] numpy.array.ma class init
Hello, we used to have this working, the latest numpy breaks it. File "/lgm/cdat/5.0.0.alpha7/lib/python2.5/site-packages/cdms2/tvariable.py", line 21, in import numpy.oldnumeric.ma as MA class TransientVariable(AbstractVariable, MA.array): TypeError: Error when calling the metaclass bases function() argument 1 must be code, not str >>> numpy.oldnumeric.ma Any suggestion on how to fix that? Thx, C Charles Doutriaux wrote: > Hi Stephan, > > Does the converter from Numeric fixes that? I mean runnning it on an old > Numeric script will import numpy.ma, does it still replace with > numpy.oldnumeric.ma? > > Thx, > > C. > > Stéfan van der Walt wrote: > >> On Wed, Mar 12, 2008 at 11:39 AM, Charles Doutriaux <[EMAIL PROTECTED]> >> wrote: >> >> >>> My mistake i was still in trunk >>> >>> but i do get: >>> >>> import numpy, numpy.oldnumeric.ma as MA, numpy.oldnumeric as >>> Numeric, PropertiedClasses >>> File >>> "/lgm/cdat/latest/lib/python2.5/site-packages/numpy/oldnumeric/ma.py", >>> line 4, in >>> from numpy.core.ma import * >>> ImportError: No module named ma >>> >>> How does one build ma these days? >>> >>> >> Travis fixed this in latest SVN. Maskedarrays should now be imported >> as numpy.ma. >> >> Regards >> Stéfan >> ___ >> Numpy-discussion mailing list >> Numpy-discussion@scipy.org >> http://projects.scipy.org/mailman/listinfo/numpy-discussion >> >> >> > ___ > Numpy-discussion mailing list > Numpy-discussion@scipy.org > http://projects.scipy.org/mailman/listinfo/numpy-discussion > > ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] numpy from subversion
Hi Stephan, Does the converter from Numeric fixes that? I mean runnning it on an old Numeric script will import numpy.ma, does it still replace with numpy.oldnumeric.ma? Thx, C. Stéfan van der Walt wrote: > On Wed, Mar 12, 2008 at 11:39 AM, Charles Doutriaux <[EMAIL PROTECTED]> wrote: > >> My mistake i was still in trunk >> >> but i do get: >> >> import numpy, numpy.oldnumeric.ma as MA, numpy.oldnumeric as >> Numeric, PropertiedClasses >> File >> "/lgm/cdat/latest/lib/python2.5/site-packages/numpy/oldnumeric/ma.py", >> line 4, in >> from numpy.core.ma import * >> ImportError: No module named ma >> >> How does one build ma these days? >> > > Travis fixed this in latest SVN. Maskedarrays should now be imported > as numpy.ma. > > Regards > Stéfan > ___ > Numpy-discussion mailing list > Numpy-discussion@scipy.org > http://projects.scipy.org/mailman/listinfo/numpy-discussion > > ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Transforming an array of numbers to an array of formatted strings
On Thu, 13 Mar 2008, Alexander Michael apparently wrote: > I want to format an array of numbers as strings. To what end? Note that tofile has a format option. And for 1d array ``x`` you can always do:: strdata = list( fmt%xi for xi in x) Nice because the counter name does not "bleed" into your program. Cheers, Alan Isaac ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] Transforming an array of numbers to an array of formatted strings
Is there a better way than looping to perform the following transformation? >>> import numpy >>> int_data = numpy.arange(1,11, dtype=int) # just an example >>> str_data = int_data.astype('S4') >>> for i in xrange(len(int_data)): ... str_data[i] = 'S%03d' % int_data[i] >>> print str_data ['S001' 'S002' 'S003' 'S004' 'S005' 'S006' 'S007' 'S008' 'S009' 'S010'] That is, I want to format an array of numbers as strings. Thanks, Alex ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Help needed with numpy 10.5 release blockers
On Wed, Mar 12, 2008 at 10:43 PM, Jarrod Millman <[EMAIL PROTECTED]> wrote: > Stefan and I also triaged the remaining tickets--closing several and > turning others in to release blockers: > > http://scipy.org/scipy/numpy/query?status=new&severity=blocker&milestone=1.0.5&order=priority > > I think that it is especially important that we spend some time trying > to make the 1.0.5 release rock solid. There are several important > changes in the trunk so I really hope we can get these tickets > resolved ASAP. I need everyone's help getting this release out. If > you can help work on any of the open release blockers, please try to > close them over the weekend. If you have any ideas about the tickets > but aren't exactly sure how to resolve them please post a message to > the list or add a comment to the ticket. Hello, I just noticed that David Cournapeau fixed one of the blockers moments after I sent out my email asking for help: http://projects.scipy.org/scipy/numpy/ticket/688 Thanks David! So we are down to 12 tickets blocking the release. Some of the tickets are just missing tests, so they should be fairly easy to implement--for anyone who wants to help get this release out ASAP. Cheers, -- Jarrod Millman Computational Infrastructure for Research Labs 10 Giannini Hall, UC Berkeley phone: 510.643.4014 http://cirl.berkeley.edu/ ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] numpy from subversion
On Wed, Mar 12, 2008 at 11:39 AM, Charles Doutriaux <[EMAIL PROTECTED]> wrote: > My mistake i was still in trunk > > but i do get: > > import numpy, numpy.oldnumeric.ma as MA, numpy.oldnumeric as > Numeric, PropertiedClasses > File > "/lgm/cdat/latest/lib/python2.5/site-packages/numpy/oldnumeric/ma.py", > line 4, in > from numpy.core.ma import * > ImportError: No module named ma > > How does one build ma these days? Travis fixed this in latest SVN. Maskedarrays should now be imported as numpy.ma. Regards Stéfan ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion