Re: [Numpy-discussion] 'nansqrt' function?

2019-02-13 Thread Mauro Cavalcanti
Thanks! I didn't heard of this package and will look into it.

Best regards,

Em Qua, 13 de fev de 2019 22:10, Robert McLeod  The `bottleneck` library is a very good package if there's some function
> in NumPy that you want to handle `nan`s in reductions without exploding.
>
> https://github.com/kwgoodman/bottleneck
>
> On Wed, Feb 13, 2019 at 12:35 PM Mauro Cavalcanti 
> wrote:
>
>> Dear ALL,
>>
>> In the process of porting an existing (but abandoned) package to the
>> latest version of Numpy, I stumbled upon a call to a 'numpy.nansqrt'
>> function, which seems not to exist.
>>
>> Here is the specific code:
>>
>> def normTrans(y):
>> denom = np.nansqrt(np.nansum(y**2))
>> return y/denom
>>
>> As far as I could find, there is no such 'nansqrt' function in the
>> current version of Numpy, so I suspect that the above code has not been
>> properly tested.
>>
>> Am I right, or that function had existed in some past version of Numpy?
>>
>> Thanks in advance for any comments or suggestions.
>>
>> Best regards,
>> ___
>> NumPy-Discussion mailing list
>> NumPy-Discussion@python.org
>> https://mail.python.org/mailman/listinfo/numpy-discussion
>>
>
>
> --
> Robert McLeod, Ph.D.
> robbmcl...@gmail.com
> robbmcl...@protonmail.com
> robert.mcl...@hitachi-hhtc.ca
> www.entropyreduction.al
>
> ___
> NumPy-Discussion mailing list
> NumPy-Discussion@python.org
> https://mail.python.org/mailman/listinfo/numpy-discussion
>
___
NumPy-Discussion mailing list
NumPy-Discussion@python.org
https://mail.python.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] 'nansqrt' function?

2019-02-13 Thread Mauro Cavalcanti
Chuck,

I attempted to find such a list from the Numpy website. A complete list
like yours should be quite handy for users if available there.

Best regards,

Em qua, 13 de fev de 2019 às 20:10, Charles R Harris <
charlesr.har...@gmail.com> escreveu:

>
>
> On Wed, Feb 13, 2019 at 2:14 PM Mauro Cavalcanti 
> wrote:
>
>> Chuck,
>>
>> Sure, using numpy.sqrt works fine.
>>
>> Thank you very much.
>>
>> Best regards,
>>
>> Em qua, 13 de fev de 2019 às 19:09, Charles R Harris <
>> charlesr.har...@gmail.com> escreveu:
>>
>>>
>>>
>>> On Wed, Feb 13, 2019 at 1:35 PM Mauro Cavalcanti 
>>> wrote:
>>>
>>>> Dear ALL,
>>>>
>>>> In the process of porting an existing (but abandoned) package to the
>>>> latest version of Numpy, I stumbled upon a call to a 'numpy.nansqrt'
>>>> function, which seems not to exist.
>>>>
>>>> Here is the specific code:
>>>>
>>>> def normTrans(y):
>>>> denom = np.nansqrt(np.nansum(y**2))
>>>> return y/denom
>>>>
>>>> As far as I could find, there is no such 'nansqrt' function in the
>>>> current version of Numpy, so I suspect that the above code has not been
>>>> properly tested.
>>>>
>>>> Am I right, or that function had existed in some past version of Numpy?
>>>>
>>>> Thanks in advance for any comments or suggestions.
>>>>
>>>>
>>> I don't recall any such function, but  nansum will not result in any
>>> nans, so plain old sqrt should work.
>>>
>>>
> Note that there are various nan stat functions:
>
> - `nanmin` -- minimum non-NaN value
> - `nanmax` -- maximum non-NaN value
> - `nanargmin` -- index of minimum non-NaN value
> - `nanargmax` -- index of maximum non-NaN value
> - `nansum` -- sum of non-NaN values
> - `nanprod` -- product of non-NaN values
> - `nancumsum` -- cumulative sum of non-NaN values
> - `nancumprod` -- cumulative product of non-NaN values
> - `nanmean` -- mean of non-NaN values
> - `nanvar` -- variance of non-NaN values
> - `nanstd` -- standard deviation of non-NaN values
> - `nanmedian` -- median of non-NaN values
> - `nanquantile` -- qth quantile of non-NaN values
> - `nanpercentile` -- qth percentile of non-NaN values
>
> Chuck
> ___
> NumPy-Discussion mailing list
> NumPy-Discussion@python.org
> https://mail.python.org/mailman/listinfo/numpy-discussion
>


-- 
Dr. Mauro J. Cavalcanti
E-mail: mauro...@gmail.com
Web: http://sites.google.com/site/maurobio
"Life is complex. It consists of real and imaginary parts."
___
NumPy-Discussion mailing list
NumPy-Discussion@python.org
https://mail.python.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] 'nansqrt' function?

2019-02-13 Thread Mauro Cavalcanti
Chuck,

Sure, using numpy.sqrt works fine.

Thank you very much.

Best regards,

Em qua, 13 de fev de 2019 às 19:09, Charles R Harris <
charlesr.har...@gmail.com> escreveu:

>
>
> On Wed, Feb 13, 2019 at 1:35 PM Mauro Cavalcanti 
> wrote:
>
>> Dear ALL,
>>
>> In the process of porting an existing (but abandoned) package to the
>> latest version of Numpy, I stumbled upon a call to a 'numpy.nansqrt'
>> function, which seems not to exist.
>>
>> Here is the specific code:
>>
>> def normTrans(y):
>> denom = np.nansqrt(np.nansum(y**2))
>> return y/denom
>>
>> As far as I could find, there is no such 'nansqrt' function in the
>> current version of Numpy, so I suspect that the above code has not been
>> properly tested.
>>
>> Am I right, or that function had existed in some past version of Numpy?
>>
>> Thanks in advance for any comments or suggestions.
>>
>>
> I don't recall any such function, but  nansum will not result in any nans,
> so plain old sqrt should work.
>
> Chuck
> ___
> NumPy-Discussion mailing list
> NumPy-Discussion@python.org
> https://mail.python.org/mailman/listinfo/numpy-discussion
>


-- 
Dr. Mauro J. Cavalcanti
E-mail: mauro...@gmail.com
Web: http://sites.google.com/site/maurobio
"Life is complex. It consists of real and imaginary parts."
___
NumPy-Discussion mailing list
NumPy-Discussion@python.org
https://mail.python.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] 'nansqrt' function?

2019-02-13 Thread Mauro Cavalcanti
Dear ALL,

In the process of porting an existing (but abandoned) package to the latest
version of Numpy, I stumbled upon a call to a 'numpy.nansqrt' function,
which seems not to exist.

Here is the specific code:

def normTrans(y):
denom = np.nansqrt(np.nansum(y**2))
return y/denom

As far as I could find, there is no such 'nansqrt' function in the current
version of Numpy, so I suspect that the above code has not been properly
tested.

Am I right, or that function had existed in some past version of Numpy?

Thanks in advance for any comments or suggestions.

Best regards,
___
NumPy-Discussion mailing list
NumPy-Discussion@python.org
https://mail.python.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Porting code for Numpy 1.13+ to get rid of "boolean index did not match indexed array along dimension 1" error

2019-02-13 Thread Mauro Cavalcanti
Eric,

Implementing either of your suggestions (swapping the lines or using an
intermediate variable) worked fine under the latest Numpy (v1.16.1)!

Thanks a lot for your help!

Best regards,

Em ter, 12 de fev de 2019 às 23:06, Eric Wieser 
escreveu:

> It looks like your code is wrong, and numpy 1.12 happened to let you get
> away with it
>
> This line:
>
> evals = evals[evals > tolerance]
>
> Reduces the eigenvalues to only those which are greater than the tolerance
>
> When you do U[:, evals > tolerance], evals > tolerance is just going to
> be [True, True, ...].
>
> You need to swap the last two lines, to
>
> U = U[:, evals > tolerance]
> evals = evals[evals > tolerance]
>
> Or better yet, introduce an intermediate variable:
>
> keep = evals > tolerance
> evals = evals[keep]
> U = U[:, keep]
>
> Eric
> ​
>
> On Tue, 12 Feb 2019 at 15:16 Mauro Cavalcanti  wrote:
>
>> Dear ALL,
>>
>> I am trying to port an eigenalysis function that runs smoothly on Numpy
>> 1.12 but fail miserably on Numpy 1.13 or higher with the dreadful error
>> "boolean index did not match indexed array along dimension 1".
>>
>> Here is a fragment of the code, where the error occurrs:
>>
>> evals, evecs = np.linalg.eig(Syy)
>> idx = evals.argsort()[::-1]
>> evals = np.real(evals[idx])
>> U = np.real(evecs[:, idx])
>> evals = evals[evals > tolerance]
>> U = U[:, evals > tolerance] # Here is where the error occurs
>>
>> So, I ask: is there a way out of this?
>>
>> Thanks in advance for any assistance you can provide.
>> ___
>> NumPy-Discussion mailing list
>> NumPy-Discussion@python.org
>> https://mail.python.org/mailman/listinfo/numpy-discussion
>>
> ___
> NumPy-Discussion mailing list
> NumPy-Discussion@python.org
> https://mail.python.org/mailman/listinfo/numpy-discussion
>


-- 
Dr. Mauro J. Cavalcanti
E-mail: mauro...@gmail.com
Web: http://sites.google.com/site/maurobio
"Life is complex. It consists of real and imaginary parts."
___
NumPy-Discussion mailing list
NumPy-Discussion@python.org
https://mail.python.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] Porting code for Numpy 1.13+ to get rid of "boolean index did not match indexed array along dimension 1" error

2019-02-12 Thread Mauro Cavalcanti
Dear ALL,

I am trying to port an eigenalysis function that runs smoothly on Numpy
1.12 but fail miserably on Numpy 1.13 or higher with the dreadful error
"boolean index did not match indexed array along dimension 1".

Here is a fragment of the code, where the error occurrs:

evals, evecs = np.linalg.eig(Syy)
idx = evals.argsort()[::-1]
evals = np.real(evals[idx])
U = np.real(evecs[:, idx])
evals = evals[evals > tolerance]
U = U[:, evals > tolerance] # Here is where the error occurs

So, I ask: is there a way out of this?

Thanks in advance for any assistance you can provide.
___
NumPy-Discussion mailing list
NumPy-Discussion@python.org
https://mail.python.org/mailman/listinfo/numpy-discussion