Re: [Numpy-discussion] preferred way of testing empty arrays

2012-01-30 Thread Chris Barker
On Fri, Jan 27, 2012 at 1:29 PM, Robert Kern  wrote:
> Well, if you really need to do this in more than one place, define a
> utility function and call it a day.
>
> def should_not_plot(x):
>    if x is None:
>        return True
>    elif isinstance(x, np.ndarray):
>        return x.size == 0
>    else:
>        return bool(x)

I tend to do things like:

def convert_to_plotable(x):
if x is None:
return None
else:
x = np.asarray(x)
if b.size == 0:
return None
return x

it does mean you need to check for None later anyway, but I like to
convert to an array early in the process -- then you know you have
either an array or None at that point.

NOTE: you could also raise and handle an exception instead.

-Chris
-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

chris.bar...@noaa.gov
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] histogram help

2012-01-30 Thread Samuel John
Hi Ruby,

I still do not fully understand your question but what I do in such cases is to 
construct a very simple array and test the functions.
The help of numpy.histogram2d or numpy.histogramdd (for more than two dims) 
might help here.

So I guess, basically you want to ignore the x,y positions and just look at the 
combined distribution of the Z values?
In this case, you would just need the numpy.histogram (the 1d version).

Note that the histogram returns the numbers and the bin-borders.

bests
 Samuel


On 30.01.2012, at 20:27, Ruby Stevenson wrote:

> Sorry, I realize I didn't describe the problem completely clear or correct.
> 
> the (x,y) in this case is just many co-ordinates, and  each coordinate
> has a list of values (Z value) associated with it.  The bins are
> allocated for the Z.
> 
> I hope this clarify things a little. Thanks again.
> 
> Ruby
> 
> 
> 
> 
> On Mon, Jan 30, 2012 at 2:21 PM, Ruby Stevenson  wrote:
>> hi, all
>> 
>> I am trying to figure out how to do histogram with numpy
>> 
>> I have a three-dimension array A[x,y,z],  another array (bins) has
>> been allocated along Z dimension, z'
>> 
>> how can I get the histogram of H[ x, y, z' ]?
>> 
>> thanks for your help.
>> 
>> Ruby
> ___
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] histogram help

2012-01-30 Thread Ruby Stevenson
Sorry, I realize I didn't describe the problem completely clear or correct.

the (x,y) in this case is just many co-ordinates, and  each coordinate
has a list of values (Z value) associated with it.  The bins are
allocated for the Z.

I hope this clarify things a little. Thanks again.

Ruby




On Mon, Jan 30, 2012 at 2:21 PM, Ruby Stevenson  wrote:
> hi, all
>
> I am trying to figure out how to do histogram with numpy
>
> I have a three-dimension array A[x,y,z],  another array (bins) has
> been allocated along Z dimension, z'
>
> how can I get the histogram of H[ x, y, z' ]?
>
> thanks for your help.
>
> Ruby
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] condense array along one dimension

2012-01-30 Thread Ruby Stevenson
I think this is exactly what I need. Thanks for your help, Olivier.

Ruby

On Fri, Jan 20, 2012 at 9:50 AM, Olivier Delalleau  wrote:
> What do you mean by "summarize"?
> If for instance you want to sum along Y, just do
>   my_array.sum(axis=1)
>
> -=- Olivier
>
> 2012/1/20 Ruby Stevenson 
>>
>> hi, all
>>
>> Say I have a three dimension array, X, Y, Z,  how can I condense into
>> two dimensions: for example, compute 2-D array with (X, Z) and
>> summarize along Y dimensions ... is it possible?
>>
>> thanks
>>
>> Ruby
>> ___
>> NumPy-Discussion mailing list
>> NumPy-Discussion@scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
>
> ___
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Addressing arrays

2012-01-30 Thread Ted To
> You'd want to update your mask appropriately to get everything you
> want to select, one criteria at a time e.g.:
> mask = a[:,0] == 1
> mask &= a[:,1] == 1960
> 
> Alternatively:
> mask = (a[:,0] == 1) & (a[:,1] == 1960)
> but be careful with the parens, & and | are normally high-priority
> bitwise operators and if you leave the parens out, it will try to
> bitwise-and 1 and a[:,1] and throw an error.
> 
> If you've got a ton of parameters, you can combine these more
> aesthetically with:
> mask = (a[:,[0,1]] == [1, 1960]).all(axis=1)
> 
> ~Brett

Zach and Brett,

Many thanks -- that is exactly what I need.

Cheers,
Ted
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Addressing arrays

2012-01-30 Thread Brett Olsen
On Mon, Jan 30, 2012 at 11:31 AM, Ted To  wrote:
> On 01/30/2012 12:13 PM, Brett Olsen wrote:
>> On Mon, Jan 30, 2012 at 10:57 AM, Ted To  wrote:
>>> Sure thing.  To keep it simple suppose I have just a two dimensional
>>> array (time,output):
>>> [(1,2),(2,3),(3,4)]
>>> I would like to look at all values of output for which, for example time==2.
>>>
>>> My actual application has a six dimensional array and I'd like to look
>>> at the contents using one or more of the first three dimensions.
>>>
>>> Many thanks,
>>> Ted
>>
>> Couldn't you just do something like this with boolean indexing:
>>
>> In [1]: import numpy as np
>>
>> In [2]: a = np.array([(1,2),(2,3),(3,4)])
>>
>> In [3]: a
>> Out[3]:
>> array([[1, 2],
>>        [2, 3],
>>        [3, 4]])
>>
>> In [4]: mask = a[:,0] == 2
>>
>> In [5]: mask
>> Out[5]: array([False,  True, False], dtype=bool)
>>
>> In [6]: a[mask,1]
>> Out[6]: array([3])
>>
>> ~Brett
>
> Thanks!  That works great if I only want to search over one index but I
> can't quite figure out what to do with more than a single index.  So
> suppose I have a labeled, multidimensional array with labels 'month',
> 'year' and 'quantity'.  a[['month','year']] gives me an array of indices
> but "a[['month','year']]==(1,1960)" produces "False".  I'm sure I simply
> don't know the proper syntax and I apologize for that -- I'm kind of new
> to numpy.
>
> Ted

You'd want to update your mask appropriately to get everything you
want to select, one criteria at a time e.g.:
mask = a[:,0] == 1
mask &= a[:,1] == 1960

Alternatively:
mask = (a[:,0] == 1) & (a[:,1] == 1960)
but be careful with the parens, & and | are normally high-priority
bitwise operators and if you leave the parens out, it will try to
bitwise-and 1 and a[:,1] and throw an error.

If you've got a ton of parameters, you can combine these more
aesthetically with:
mask = (a[:,[0,1]] == [1, 1960]).all(axis=1)

~Brett
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Addressing arrays

2012-01-30 Thread Zachary Pincus
> Thanks!  That works great if I only want to search over one index but I
> can't quite figure out what to do with more than a single index.  So
> suppose I have a labeled, multidimensional array with labels 'month',
> 'year' and 'quantity'.  a[['month','year']] gives me an array of indices
> but "a[['month','year']]==(1,1960)" produces "False".  I'm sure I simply
> don't know the proper syntax and I apologize for that -- I'm kind of new
> to numpy.

I think that your best bet is to form the boolean masks independently and then 
logical-and them together:

mask = (a['month'] == 1) & (a['year'] == 1960)
jan_60 = a[mask]

Someone might have more insight here. Though I should note that if you have 
large data and are doing lots of "queries" like this, a more database-ish 
approach might be better. Something like sqlite's python bindings, or PyTables. 
Alternately, if your data are all time-series based things, PANDAS might be 
worth looking at. 

But the above approach should be just fine for non-huge datasets...

Zach
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Addressing arrays

2012-01-30 Thread Ted To
On 01/30/2012 12:13 PM, Brett Olsen wrote:
> On Mon, Jan 30, 2012 at 10:57 AM, Ted To  wrote:
>> Sure thing.  To keep it simple suppose I have just a two dimensional
>> array (time,output):
>> [(1,2),(2,3),(3,4)]
>> I would like to look at all values of output for which, for example time==2.
>>
>> My actual application has a six dimensional array and I'd like to look
>> at the contents using one or more of the first three dimensions.
>>
>> Many thanks,
>> Ted
> 
> Couldn't you just do something like this with boolean indexing:
> 
> In [1]: import numpy as np
> 
> In [2]: a = np.array([(1,2),(2,3),(3,4)])
> 
> In [3]: a
> Out[3]:
> array([[1, 2],
>[2, 3],
>[3, 4]])
> 
> In [4]: mask = a[:,0] == 2
> 
> In [5]: mask
> Out[5]: array([False,  True, False], dtype=bool)
> 
> In [6]: a[mask,1]
> Out[6]: array([3])
> 
> ~Brett

Thanks!  That works great if I only want to search over one index but I
can't quite figure out what to do with more than a single index.  So
suppose I have a labeled, multidimensional array with labels 'month',
'year' and 'quantity'.  a[['month','year']] gives me an array of indices
but "a[['month','year']]==(1,1960)" produces "False".  I'm sure I simply
don't know the proper syntax and I apologize for that -- I'm kind of new
to numpy.

Ted
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Addressing arrays

2012-01-30 Thread Brett Olsen
On Mon, Jan 30, 2012 at 10:57 AM, Ted To  wrote:
> Sure thing.  To keep it simple suppose I have just a two dimensional
> array (time,output):
> [(1,2),(2,3),(3,4)]
> I would like to look at all values of output for which, for example time==2.
>
> My actual application has a six dimensional array and I'd like to look
> at the contents using one or more of the first three dimensions.
>
> Many thanks,
> Ted

Couldn't you just do something like this with boolean indexing:

In [1]: import numpy as np

In [2]: a = np.array([(1,2),(2,3),(3,4)])

In [3]: a
Out[3]:
array([[1, 2],
   [2, 3],
   [3, 4]])

In [4]: mask = a[:,0] == 2

In [5]: mask
Out[5]: array([False,  True, False], dtype=bool)

In [6]: a[mask,1]
Out[6]: array([3])

~Brett
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Addressing arrays

2012-01-30 Thread Ted To
Sure thing.  To keep it simple suppose I have just a two dimensional
array (time,output):
[(1,2),(2,3),(3,4)]
I would like to look at all values of output for which, for example time==2.

My actual application has a six dimensional array and I'd like to look
at the contents using one or more of the first three dimensions.

Many thanks,
Ted

On 01/30/2012 10:50 AM, Zachary Pincus wrote:
> Ted, can you clarify what you're asking for? Maybe give a trivial example of 
> an array and the desired output?
> 
> I'm pretty sure this is a slicing question though:
>> If I have a three dimensional array a=(x,y,z), can I look at the values of z 
>> given particular values for x and y?
> Given that element values are scalars in this case, and indices are (x,y,z) 
> triples, it seems likely that looking for "values of z" given an (x,y) pair 
> is an slicing-by-index question, no?
> 
> For indexing-by-value, "fancy indexing" with boolean masks is usually the way 
> to go... again, Ted (or Chao), if you can describe your indexing needs in a 
> bit more detail, it's often easy to find a compact slicing and/or 
> fancy-indexing strategy that works well and reasonably efficiently.
> 
> Zach
> 
> 
> 
> On Jan 30, 2012, at 10:33 AM, Chao YUE wrote:
> 
>> he is not asking for slicing. he is asking for how to index array by element 
>> value but not element index.
>>
>> 2012/1/30 Zachary Pincus 
>> a[x,y,:]
>>
>> Read the slicing part of the tutorial:
>> http://www.scipy.org/Tentative_NumPy_Tutorial
>> (section 1.6)
>>
>> And the documentation:
>> http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html
>>
>>
>>
>> On Jan 30, 2012, at 10:25 AM, Ted To wrote:
>>
>>> Hi,
>>>
>>> Is there some straightforward way to access an array by values across a
>>> subset of its dimensions?  For example, if I have a three dimensional
>>> array a=(x,y,z), can I look at the values of z given particular values
>>> for x and y?
>>>
>>> Thanks,
>>> Ted
>>> ___
>>> NumPy-Discussion mailing list
>>> NumPy-Discussion@scipy.org
>>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>>
>> ___
>> NumPy-Discussion mailing list
>> NumPy-Discussion@scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>>
>>
>>
>> -- 
>> ***
>> Chao YUE
>> Laboratoire des Sciences du Climat et de l'Environnement (LSCE-IPSL)
>> UMR 1572 CEA-CNRS-UVSQ
>> Batiment 712 - Pe 119
>> 91191 GIF Sur YVETTE Cedex
>> Tel: (33) 01 69 08 29 02; Fax:01.69.08.77.16
>> 
>>
>> ___
>> NumPy-Discussion mailing list
>> NumPy-Discussion@scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
> 
> ___
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Addressing arrays

2012-01-30 Thread Zachary Pincus
Ted, can you clarify what you're asking for? Maybe give a trivial example of an 
array and the desired output?

I'm pretty sure this is a slicing question though:
> If I have a three dimensional array a=(x,y,z), can I look at the values of z 
> given particular values for x and y?
Given that element values are scalars in this case, and indices are (x,y,z) 
triples, it seems likely that looking for "values of z" given an (x,y) pair is 
an slicing-by-index question, no?

For indexing-by-value, "fancy indexing" with boolean masks is usually the way 
to go... again, Ted (or Chao), if you can describe your indexing needs in a bit 
more detail, it's often easy to find a compact slicing and/or fancy-indexing 
strategy that works well and reasonably efficiently.

Zach



On Jan 30, 2012, at 10:33 AM, Chao YUE wrote:

> he is not asking for slicing. he is asking for how to index array by element 
> value but not element index.
> 
> 2012/1/30 Zachary Pincus 
> a[x,y,:]
> 
> Read the slicing part of the tutorial:
> http://www.scipy.org/Tentative_NumPy_Tutorial
> (section 1.6)
> 
> And the documentation:
> http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html
> 
> 
> 
> On Jan 30, 2012, at 10:25 AM, Ted To wrote:
> 
> > Hi,
> >
> > Is there some straightforward way to access an array by values across a
> > subset of its dimensions?  For example, if I have a three dimensional
> > array a=(x,y,z), can I look at the values of z given particular values
> > for x and y?
> >
> > Thanks,
> > Ted
> > ___
> > NumPy-Discussion mailing list
> > NumPy-Discussion@scipy.org
> > http://mail.scipy.org/mailman/listinfo/numpy-discussion
> 
> ___
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
> 
> 
> 
> -- 
> ***
> Chao YUE
> Laboratoire des Sciences du Climat et de l'Environnement (LSCE-IPSL)
> UMR 1572 CEA-CNRS-UVSQ
> Batiment 712 - Pe 119
> 91191 GIF Sur YVETTE Cedex
> Tel: (33) 01 69 08 29 02; Fax:01.69.08.77.16
> 
> 
> ___
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Addressing arrays

2012-01-30 Thread Chao YUE
he is not asking for slicing. he is asking for how to index array by
element value but not element index.

2012/1/30 Zachary Pincus 

> a[x,y,:]
>
> Read the slicing part of the tutorial:
> http://www.scipy.org/Tentative_NumPy_Tutorial
> (section 1.6)
>
> And the documentation:
> http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html
>
>
>
> On Jan 30, 2012, at 10:25 AM, Ted To wrote:
>
> > Hi,
> >
> > Is there some straightforward way to access an array by values across a
> > subset of its dimensions?  For example, if I have a three dimensional
> > array a=(x,y,z), can I look at the values of z given particular values
> > for x and y?
> >
> > Thanks,
> > Ted
> > ___
> > NumPy-Discussion mailing list
> > NumPy-Discussion@scipy.org
> > http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
> ___
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>



-- 
***
Chao YUE
Laboratoire des Sciences du Climat et de l'Environnement (LSCE-IPSL)
UMR 1572 CEA-CNRS-UVSQ
Batiment 712 - Pe 119
91191 GIF Sur YVETTE Cedex
Tel: (33) 01 69 08 29 02; Fax:01.69.08.77.16

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Addressing arrays

2012-01-30 Thread Zachary Pincus
a[x,y,:]

Read the slicing part of the tutorial:
http://www.scipy.org/Tentative_NumPy_Tutorial 
(section 1.6)

And the documentation:
http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html



On Jan 30, 2012, at 10:25 AM, Ted To wrote:

> Hi,
> 
> Is there some straightforward way to access an array by values across a
> subset of its dimensions?  For example, if I have a three dimensional
> array a=(x,y,z), can I look at the values of z given particular values
> for x and y?
> 
> Thanks,
> Ted
> ___
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Addressing arrays

2012-01-30 Thread Malcolm Reynolds
On Mon, Jan 30, 2012 at 3:25 PM, Ted To  wrote:
> Is there some straightforward way to access an array by values across a
> subset of its dimensions?  For example, if I have a three dimensional
> array a=(x,y,z), can I look at the values of z given particular values
> for x and y?

a[x, y, :] should get you what you want I believe..

Malcolm
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Addressing arrays

2012-01-30 Thread Chao YUE
I am afraid you have to write index inquire function by yourself. I did
like this.

chao

2012/1/30 Ted To 

> Hi,
>
> Is there some straightforward way to access an array by values across a
> subset of its dimensions?  For example, if I have a three dimensional
> array a=(x,y,z), can I look at the values of z given particular values
> for x and y?
>
> Thanks,
> Ted
> ___
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>



-- 
***
Chao YUE
Laboratoire des Sciences du Climat et de l'Environnement (LSCE-IPSL)
UMR 1572 CEA-CNRS-UVSQ
Batiment 712 - Pe 119
91191 GIF Sur YVETTE Cedex
Tel: (33) 01 69 08 29 02; Fax:01.69.08.77.16

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] Addressing arrays

2012-01-30 Thread Ted To
Hi,

Is there some straightforward way to access an array by values across a
subset of its dimensions?  For example, if I have a three dimensional
array a=(x,y,z), can I look at the values of z given particular values
for x and y?

Thanks,
Ted
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Unrealistic expectations of class Polynomial or a bug?

2012-01-30 Thread eat
On Sat, Jan 28, 2012 at 11:14 PM, Charles R Harris <
charlesr.har...@gmail.com> wrote:

>
>
> On Sat, Jan 28, 2012 at 11:15 AM, eat  wrote:
>
>> Hi,
>>
>> Short demonstration of the issue:
>> In []: sys.version
>> Out[]: '2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit
>> (Intel)]'
>> In []: np.version.version
>> Out[]: '1.6.0'
>>
>> In []: from numpy.polynomial import Polynomial as Poly
>> In []: def p_tst(c):
>>..: p= Poly(c)
>>..: r= p.roots()
>>..: return sort(abs(p(r)))
>>..:
>>
>> Now I would expect a result more like:
>> In []: p_tst(randn(123))[-3:]
>> Out[]: array([  3.41987203e-07,   2.82123675e-03,   2.82123675e-03])
>>
>> be the case, but actually most result seems to be more like:
>> In []: p_tst(randn(123))[-3:]
>> Out[]: array([  9.09325898e+13,   9.09325898e+13,   1.29387029e+72])
>> In []: p_tst(randn(123))[-3:]
>> Out[]: array([  8.60862087e-11,   8.60862087e-11,   6.58784520e+32])
>> In []: p_tst(randn(123))[-3:]
>> Out[]: array([  2.00545673e-09,   3.25537709e+32,   3.25537709e+32])
>> In []: p_tst(randn(123))[-3:]
>> Out[]: array([  3.22753481e-04,   1.87056454e+00,   1.87056454e+00])
>> In []: p_tst(randn(123))[-3:]
>> Out[]: array([  2.98556327e+08,   2.98556327e+08,   8.23588003e+12])
>>
>> So, does this phenomena imply that
>> - I'm testing with too high order polynomials (if so, does there exists a
>> definite upper limit of polynomial order I'll not face this issue)
>> or
>> - it's just the 'nature' of computations with float values (if so,
>> probably I should be able to tackle this regardless of the polynomial order)
>> or
>> - it's a nasty bug in class Polynomial
>>
>>
> It's a defect. You will get all the roots and the number will equal the
> degree. I haven't decided what the best way to deal with this is, but my
> thoughts have trended towards specifying an interval with the default being
> the domain. If you have other thoughts I'd be glad for the feedback.
>
> For the problem at hand, note first that you are specifying the
> coefficients, not the roots as was the case with poly1d. Second, as a rule
> of thumb, plain old polynomials will generally only be good for degree < 22
> due to being numerically ill conditioned. If you are really looking to use
> high degrees, Chebyshev or Legendre will work better, although you will
> probably need to explicitly specify the domain. If you want to specify the
> polynomial using roots, do Poly.fromroots(...). Third, for the high degrees
> you are probably screwed anyway for degree 123, since the accuracy of the
> root finding will be limited, especially for roots that can cluster, and
> any root that falls even a little bit outside the interval [-1,1] (the
> default domain) is going to evaluate to a big number simply because the
> polynomial is going to h*ll at a rate you wouldn't believe ;)
>
> For evenly spaced roots in [-1, 1] and using Chebyshev polynomials, things
> look good for degree 50, get a bit loose at degree 75 but can be fixed up
> with one iteration of Newton, and blow up at degree 100. I think that's
> pretty good, actually, doing better would require a lot more work. There
> are some zero finding algorithms out there that might do better if someone
> wants to give it a shot.
>
> In [20]: p = Cheb.fromroots(linspace(-1, 1, 50))
>
> In [21]: sort(abs(p(p.roots(
> Out[21]:
> array([  6.20385459e-25,   1.65436123e-24,   2.06795153e-24,
>  5.79026429e-24,   5.89366186e-24,   6.44916482e-24,
>  6.44916482e-24,   6.77254127e-24,   6.97933642e-24,
>  7.25459208e-24,   1.00295649e-23,   1.37391414e-23,
>  1.37391414e-23,   1.63368171e-23,   2.39882378e-23,
>  3.30872245e-23,   4.38405725e-23,   4.49502653e-23,
>  4.49502653e-23,   5.58346913e-23,   8.35452419e-23,
>  9.38407760e-23,   9.38407760e-23,   1.03703218e-22,
>  1.03703218e-22,   1.23249911e-22,   1.75197880e-22,
>  1.75197880e-22,   3.07711188e-22,   3.09821786e-22,
>  3.09821786e-22,   4.56625520e-22,   4.56625520e-22,
>  4.69638303e-22,   4.69638303e-22,   5.96448724e-22,
>  5.96448724e-22,   1.24076485e-21,   1.24076485e-21,
>  1.59972624e-21,   1.59972624e-21,   1.62930347e-21,
>  1.62930347e-21,   1.73773328e-21,   1.73773328e-21,
>  1.87935435e-21,   2.30287083e-21,   2.48815928e-21,
>  2.85411753e-21,   2.85411753e-21])
>
Thanks,

for a very informative feedback. I'll study those orthogonal polynomials
more detail.


Regards,
- eat

>
>
> Chuck
>
> ___
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion