Hi All,
Any reason why this:
import numpy
numpy.zeros(10)[-123]
Traceback (most recent call last):
File stdin, line 1, in module
IndexError: index out of bounds
...could say this:
numpy.zeros(10)[-123]
Traceback (most recent call last):
File stdin, line 1, in module
IndexError:
On 01/06/2012 16:39, Benjamin Root wrote:
import numpy
numpy.zeros(10)[-123]
Traceback (most recent call last):
File stdin, line 1, in module
IndexError: index out of bounds
...could say this:
numpy.zeros(10)[-123]
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
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
On 22/08/2011 00:18, Mark Dickinson wrote:
On Sun, Aug 21, 2011 at 1:08 AM, Robert Kernrobert.k...@gmail.com 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
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
On 20/08/2011 15:38, Robert Kern wrote:
On Sat, Aug 20, 2011 at 17:37, Chris Withersch...@simplistix.co.uk 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)
dtype=object
Thanks!
What
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 had
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?
cheers,
Chris
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
Thanks for this, very informative! :-)
Chris
On 06/10/2010 17:35, Friedrich Romstedt wrote:
2010/10/5 Chris Withersch...@simplistix.co.uk:
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
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
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
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:
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 the
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.
help:
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 NaNs
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
-
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 or not.
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
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(result)
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
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 portion
of
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:
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
___
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)
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
--
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 a
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?
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
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
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:
import numpy as N?
Yep
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 in
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 got
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
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
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])
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. write some
Small problem
38 matches
Mail list logo