Re: [Numpy-discussion] better error message possible?

2012-06-01 Thread Chris Withers
On 01/06/2012 16:39, Benjamin Root wrote: > > > > >>> import numpy > > >>> numpy.zeros(10)[-123] > > Traceback (most recent call last): > > File "", line 1, in > > IndexError: index out of bounds > > > > ...could say this: > > > > >>> numpy.zeros(10)[

[Numpy-discussion] better error message possible?

2012-06-01 Thread Chris Withers
Hi All, Any reason why this: >>> import numpy >>> numpy.zeros(10)[-123] Traceback (most recent call last): File "", line 1, in IndexError: index out of bounds ...could say this: >>> numpy.zeros(10)[-123] Traceback (most recent call last): File "", line 1, in IndexError: -123 is out o

Re: [Numpy-discussion] indexes in an array where value is greater than 1?

2012-05-27 Thread Chris Withers
On 25/05/2012 16:21, Benjamin Root wrote: > > np.nonzero(arrrgh > 1) Did you mean np.where(arrrgh > 1)? I didn't know you could use np.nonzero in the way your describe? Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk _

[Numpy-discussion] indexes in an array where value is greater than 1?

2012-05-25 Thread Chris Withers
Hi All, I have an array: arrrgh = numpy.zeros(1) A sparse collection of elements will have values greater than zero: arrrgh[] = 2 arrrgh[3453453] =42 The *wrong* way to do this is: for i in xrange(len(arrrgh)): if arrrgh[i] > 1: print i What's the right way? Chris

Re: [Numpy-discussion] Decimal arrays?

2011-08-22 Thread Chris Withers
On 22/08/2011 00:18, Mark Dickinson wrote: > On Sun, Aug 21, 2011 at 1:08 AM, Robert Kern wrote: >> You may want to try the cdecimal package: >> >> http://pypi.python.org/pypi/cdecimal/ > > I'll second this suggestion. cdecimal is an extraordinarily carefully > written and well-tested (almost)

[Numpy-discussion] saving groups of numpy arrays to disk

2011-08-20 Thread Chris Withers
Hi All, I've got a tree of nested dicts that at their leaves end in numpy arrays of identical sizes. What's the easiest way to persist these to disk so that I can pick up with them where I left off? What's the most "correct" way to do so? I'm using IPython if that makes things easier... I ha

Re: [Numpy-discussion] Decimal arrays?

2011-08-20 Thread Chris Withers
On 20/08/2011 15:38, Robert Kern wrote: > On Sat, Aug 20, 2011 at 17:37, Chris Withers wrote: >> Hi All, >> >> What's the best type of array to use for decimal values? >> (ie: where I care about precision and want to avoid any possible >> rounding errors) &

[Numpy-discussion] Decimal arrays?

2011-08-20 Thread Chris Withers
Hi All, What's the best type of array to use for decimal values? (ie: where I care about precision and want to avoid any possible rounding errors) cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk

Re: [Numpy-discussion] summing an array

2011-08-19 Thread Chris Withers
On 18/08/2011 07:58, Bob Dowling wrote: > > >>> numpy.add.accumulate(a) > array([ 0, 1, 3, 6, 10]) > > >>> numpy.add.accumulate(a, out=a) > array([ 0, 1, 3, 6, 10]) What's the difference between numpy.cumsum and numpy.add.accumulate? Where can I find the reference docs for these? che

[Numpy-discussion] summing an array

2011-08-18 Thread Chris Withers
Hi All, Hopefully a simple newbie question, if I have an array such as : array([0, 1, 2, 3, 4]) ...what's the best way to cummulatively sum it so that I end up with: array([0, 1, 3, 6, 10]) How would I do this both in-place and to create a new array? cheers, Chris -- Simplistix - Content M

Re: [Numpy-discussion] ufunc.accumulate question

2010-10-08 Thread Chris Withers
Thanks for this, very informative! :-) Chris On 06/10/2010 17:35, Friedrich Romstedt wrote: > 2010/10/5 Chris Withers: >> Hi All, >> >> I can't find any docs on this behavior. >> >> So, I have a python function. To keep it simple, lets just do additio

Re: [Numpy-discussion] index of a value in an array

2010-10-06 Thread Chris Withers
On 06/10/2010 14:53, Thomas, Brian (GE Energy) wrote: > For e.g. to find index of number 1 in array a, you can say > idx = where(a==1) Exactly what we were looking for, thanks! Chris ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://ma

[Numpy-discussion] index of a value in an array

2010-10-06 Thread Chris Withers
Hi All, Given an array such as: array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) How can I find the index of a particular number in the array? (ie: if it was a list, I'd do [1,2,3,4].index(3)) cheers, Chris ___ NumPy-Discussion mailing list NumPy-Discussion@sc

[Numpy-discussion] ufunc.accumulate question

2010-10-05 Thread Chris Withers
Hi All, I can't find any docs on this behavior. So, I have a python function. To keep it simple, lets just do addition: def add(x,y): print x,y retun x+y So, I can turn this into a ufunc as follows: uadd = np.frompyfunc(add,2,1) Now, I can apply it to an array: >>> uadd.accumulate(np.

[Numpy-discussion] Tutorial on working with Excel files in Python (without COM and cross platform!) at PyConUS 2009

2009-01-22 Thread Chris Withers
Hi All, Too many people in the Python community think the only way to work with Excel files in Python is using COM on Windows. To try and correct this, I'm giving a tutorial at this year's PyCon in Chicago on Wednesday, 25th March that will cover working with Excel files in Python using the pur

Re: [Numpy-discussion] bug with with fill_values in masked arrays?

2008-03-26 Thread Chris Withers
Pierre GM wrote: > My bad, I neglected an overall doc for the functions and their docstring. But > you know what ? As you're now at an intermediary level, That's pretty unkind to your userbase. I know a lot about python, but I'm a total novice with numpy and even the maths it's based on. > hel

Re: [Numpy-discussion] bug with with fill_values in masked arrays?

2008-03-26 Thread Chris Withers
Matt Knox wrote: > data = [1., 2., 3., np.nan, 5., 6.] > mask = [0, 0, 0, 1, 0, 0] I'm creating the ma with ma.masked_where... > marr = ma.array(data, mask=mask) > marr.set_fill_value(55) > print marr[0] is ma.masked # False > print marr[3] # ma.masked constant Yeah, and this is where I have th

Re: [Numpy-discussion] bug with with fill_values in masked arrays?

2008-03-25 Thread Chris Withers
Pierre GM wrote: > > Well, yeah, my bad, that depends on whether you use masked_invalid or > fix_invalid or just build a basic masked array. Yeah, well, if there were any docs I'd have a *clue* what you were talking about ;-) y=ma.fix_invalid(x) I've never done this ;-) > Having

Re: [Numpy-discussion] dunno what array operation I'm looking for...

2008-03-22 Thread Chris Withers
Joris De Ridder wrote: > numpy.diff > See http://www.scipy.org/Numpy_Example_List Cool :-) Both this and Hoyt's example do exactly what I want. I'm guessing diff is going to be more efficient though? cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - htt

[Numpy-discussion] dunno what array operation I'm looking for...

2008-03-21 Thread Chris Withers
Hi All, Say I have an array like: >>> measurements = array([100,109,115,117]) What do I do to it to get: array([9, 6, 2]) Is the following really the best way? >>> result = [] >>> for i in range(1,len(measurements)): ... result.append(measurements[i]-measurements[i-1]) ... >>> array(res

Re: [Numpy-discussion] bug with with fill_values in masked arrays?

2008-03-21 Thread Chris Withers
Pierre GM wrote: > On Wednesday 19 March 2008 19:47:37 Matt Knox wrote: >>> 1. why am I not getting my NaN's back? > > Because they're gone when you create your masked array. Really? At least one other post has disagreed with that. And it does seem odd that a value, even if it's a nan, would be

Re: [Numpy-discussion] bug with with fill_values in masked arrays?

2008-03-21 Thread Chris Withers
Pierre GM wrote: >> This sucks to the point of feeling like a bug :-( > > It is not. Ignoring the fill value of masked array feels like a bug to me... >> Why is it desirable for it to behave like this? > > Because that way, you can compare anything to masked and see whether a value > is masked

Re: [Numpy-discussion] isnan bug?

2008-03-20 Thread Chris Withers
Eric Firing wrote: > I don't see why you consider this a bug. isnan tests whether an > instance of a numeric type is a nan or not; Why does it limit to numeric types? isnan sounds pretty boolean to me, anything that isn't nan should return False, regardless of type, in the same way as I can do:

Re: [Numpy-discussion] documentation for masked arrays?

2008-03-20 Thread Chris Withers
Jarrod Millman wrote: > > There is a documentation day on Friday. If you have some time, it > would be great if you could help out with writing NumPy docstrings. > There more people who contribute, the faster this will happen. It's a catch 22, I don't have the knowledge to usefully do this :-(

Re: [Numpy-discussion] bug with with fill_values in masked arrays?

2008-03-20 Thread Chris Withers
Matt Knox wrote: >> 1. why am I not getting my NaN's back? > > when iterating over a masked array, you get the "ma.masked" constant for > elements that were masked (same as what you would get if you indexed the > masked > array at that element). If you are referring specifically to the .data port

[Numpy-discussion] isnan bug?

2008-03-20 Thread Chris Withers
Hi All, I'm faily sure that: numpy.isnan(datetime.datetime.now()) ...should just return False and not raise an exception. Where can I raise a bug to this effect? cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk

Re: [Numpy-discussion] documentation for masked arrays?

2008-03-19 Thread Chris Withers
Bill Spotz wrote: > I have found that any search on that document containing an > underscore will turn up zero matches. Substitute a space instead. That's not been my experience. I found the *one* mention of fill_value just fine, the coverage of masked arrays is woeful :-( Chris -- Simplist

[Numpy-discussion] bug with with fill_values in masked arrays?

2008-03-19 Thread Chris Withers
OK, my specific problem with masked arrays is as follows: >>> a = numpy.array([1,numpy.nan,2]) >>> aa = numpy.ma.masked_where(numpy.isnan(a),a) >>> aa array(data = [ 1.e+00 1.e+20 2.e+00], mask = [False True False], fill_value=1e+020) >>> numpy.

[Numpy-discussion] documentation for masked arrays?

2008-03-19 Thread Chris Withers
Hi All, Where can I find docs for masked arrays? The "paid for" book doesn't even contain the phrase "masked_where" :-( cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk ___ Numpy-dis

Re: [Numpy-discussion] how to build a series of arrays as I go?

2008-03-18 Thread Chris Withers
Alexander Michael wrote: > Be default (if I understand correctly) the passing a regular array to > MaskedArray will not copy it, so it less redundant than it may at > first appear. The MaskedArray provides as masked *view* of the > underlying array data you give it. Cool, that was exactly what I w

Re: [Numpy-discussion] newbie question - summing a list of arrays

2008-03-18 Thread Chris Withers
Alan G Isaac wrote: > Again: > http://www.scipy.org/Numpy_Example_List_With_Doc > > Really, as a new NumPy user you should just keep > this page open in your browser. Point well made, it's a shame that summary doesn't form part of the book... > Also, help(N.sum), of course. Ah cool. I think I g

Re: [Numpy-discussion] newbie question - summing a list of arrays

2008-03-18 Thread Chris Withers
Manuel Metz wrote: > Hm, in this case you can do it like this: > > numpy.sum(numpy.array([numpy.sum(v) for k,v in data.items()])) maybe: numpy.num(data.values(),axis=0) ...would also work? I can't actually use that though as the reason I need to do this is part of building stacked bar charts

Re: [Numpy-discussion] newbie question - summing a list of arrays

2008-03-18 Thread Chris Withers
Alan G Isaac wrote: > On Tue, 18 Mar 2008, Chris Withers apparently wrote: >> Say I have an aribtary number of arrays: >> arrays = [array([1,2,3]),array([4,5,6]),array([7,8,9])] >> How can I sum these all together? > > Try N.sum(arrays,axis=0). I assume N here is:

Re: [Numpy-discussion] new question - summing a list of arrays

2008-03-18 Thread Chris Withers
Keith Goodman wrote: >>> sum(x) > > matrix([[ 1.15063313], > [ 0.8841396 ], > [ 1.7370669 ]]) When these are arrays, I just get a single number sum back... Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk _

[Numpy-discussion] new question - summing a list of arrays

2008-03-18 Thread Chris Withers
Hi All, Say I have an aribtary number of arrays: arrays = [array([1,2,3]),array([4,5,6]),array([7,8,9])] How can I sum these all together? My only solution so far is this: sum = arrays[0] for a in arrays[1:]: sum += a ...which is ugly :-S cheers, Chris -- Simplistix - Content Manageme

Re: [Numpy-discussion] how to build a series of arrays as I go?

2008-03-18 Thread Chris Withers
Travis E. Oliphant wrote: > Generally, arrays are not efficiently re-sized. It is best to > pre-allocate, or simply create a list by appending and then convert to > an array after the fact as you have done. True, although that feels like iterating over the data twice for no reason, which feels

Re: [Numpy-discussion] how to build a series of arrays as I go?

2008-03-18 Thread Chris Withers
Robert Kern wrote: > Appending to a list is almost always better than growing an array by > concatenation. If you have a real need for speed, though, there are a > few tricks you can do at the expense of complexity. I don't for this project but I might in future, where can I read about this? chee

Re: [Numpy-discussion] how to build a series of arrays as I go?

2008-03-17 Thread Chris Withers
Alan G Isaac wrote: > On Mon, 17 Mar 2008, Chris Withers apparently wrote: >> woefully inadequate state of the currently available free >> documentation > > 1. http://www.scipy.org/Numpy_Example_List_With_Doc Yeah, read that, wood, trees, can't tell the... > 2. w

Re: [Numpy-discussion] how to build a series of arrays as I go?

2008-03-17 Thread Chris Withers
Charles Doutriaux wrote: > 1-)You could use the concatenate function to grow an array as you go. Thanks. Would it be more efficient to build the whole set of arrays as lists first or build them as arrays and use concatenate? > 2-) assumnig you still have your list > > b=numpy.array(data[name])

[Numpy-discussion] how to build a series of arrays as I go?

2008-03-17 Thread Chris Withers
Hi All, I'm using xlrd to read an excel workbook containing several columns of data as follows: for r in range(1,sheet.nrows): date = \ datetime(*xlrd.xldate_as_tuple(sheet.cell_value(r,0),book.datemode)) if date_cut_off and date < date_cut_off: continue for c in range(le