Re: [Numpy-discussion] numpy histogram data

2021-06-07 Thread Keith Sloan
Thanks

Not sure where I get centers & edges from

# Plot of Histogram of Stacked Counts of Red elliptical Galaxies versus
Red Shift
REMrange1 =
RedEllipticalMasses[RedEllipticalMasses[RedEllipticalMasses['uminusr']>1.8]['uminusr']
<2.0]
print(len(REMrange1))
counts1, bins1 = np.histogram(REMrange1['Z_1'],bins=bins)
REMrange2a = RedEllipticalMasses[RedEllipticalMasses['uminusr']>2.0]
REMrange2 = REMrange2a[REMrange2a['uminusr'] <2.2]
counts2, bins2 = np.histogram(REMrange2['Z_1'],bins=bins)
REMrange3a = RedEllipticalMasses[RedEllipticalMasses['uminusr']>2.2]
REMrange3 = REMrange3a[REMrange3a['uminusr'] <2.4]
counts3, bins3 = np.histogram(REMrange3['Z_1'],bins=bins)
REMrange4a = RedEllipticalMasses[RedEllipticalMasses['uminusr']>2.4]
REMrange4 = REMrange4a[REMrange4a['uminusr'] <2.6]
counts4, bins4 = np.histogram(REMrange4['Z_1'],bins=bins)
REMrange5a = RedEllipticalMasses[RedEllipticalMasses['uminusr']>2.6]
REMrange5 = REMrange5a[REMrange5a['uminusr'] <2.8]
counts5, bins5 = np.histogram(REMrange5['Z_1'],bins=bins)
counts = [counts1, counts2, counts3, counts4, counts5] 
centers = [centers for _ in counts] 
fig, ax = plt.subplots(1, 1, figsize=(12,8)) # make the figure with the size
10 x 8 inches
fig.suptitle("2 - Histogram Counts of Red Galaxies versus Redshift")
ax.set_xlabel('Redshift Z')
ax.set_ylabel('Counts of Galaxies')
plt.hist(centers, bins=bins, weights=counts, stacked=True)
plt.show()

Barfs on
NameError Traceback (most recent call last)
 in 
 53 counts5, bins5 = np.histogram(REMrange5['Z_1'],bins=bins)
 54 counts = [counts1, counts2, counts3, counts4, counts5]
---> 55 centers = [centers for _ in counts]
 56 fig, ax = plt.subplots(1, 1, figsize=(12,8)) # make the figure with
the size 10 x 8 inches
 57 fig.suptitle("2 - Histogram Counts of Red Galaxies versus Redshift")



--
Sent from: http://numpy-discussion.10968.n7.nabble.com/
___
NumPy-Discussion mailing list
NumPy-Discussion@python.org
https://mail.python.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] numpy histogram data

2021-06-07 Thread Doug Davis
Keith Sloan  writes:

> Thanks
>
> Not sure where I get centers & edges from

Every time you call np.histogram the second return will be an array of
edges; so you define centers anywhere after your first np.histogram
call, e.g. with your bins1 variable. (I can't tell if this is exactly
the case, but it looks like you are pre-defining your bin edges in the
`bins` variable, which would allow you to use that as well.)

>
> # Plot of Histogram of Stacked Counts of Red elliptical Galaxies versus
> Red Shift
> REMrange1 =
> RedEllipticalMasses[RedEllipticalMasses[RedEllipticalMasses['uminusr']>1.8]['uminusr']
> <2.0]
> print(len(REMrange1))
> counts1, bins1 = np.histogram(REMrange1['Z_1'],bins=bins)

After this line if bins is an array of bin edges it just gets copied to
bins1. (the edges return is useful when bins are defined with an integer
(total number) and range is a tuple (xmin, xmin)). So you can define
centers with:

centers = 0.5 * (bins1[1:] + bins1[:-1]
___
NumPy-Discussion mailing list
NumPy-Discussion@python.org
https://mail.python.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] RFC: supporting complex inputs in np.logaddexp

2021-06-07 Thread Ralf Gommers
On Tue, Jun 1, 2021 at 3:18 PM Filippo Vicentini 
wrote:

> Hello all,
>
> I would like to ask if the maintainers would be in favour of adding
> support to np.logaddexp in order to support complex numbers.
> scipy.special.logsumexp already does, and it would be relatively
> straightforward to support them in numpy too.
>

That may just work by accident in SciPy, it's not tested in
`scipy/special/tests/test_logsumexp.py`. Probably because it's implemented
in pure Python. If you rely on that, adding a few tests would be nice.

Adding support to `np.logaddexp` seems fine to me.

Cheers,
Ralf



> Complex numbers are very common when working in quantum physics, where we
> have complex-valued probability amplitudes.
>
> Best,
> Filippo Vicentini
> ___
> 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


[Numpy-discussion] Accepting NEP 35 `like=array_like` for use with `__array_function__`

2021-06-07 Thread Sebastian Berg
Hi all,

I have opened a PR (https://github.com/numpy/numpy/pull/19188) to
*finalize* NEP 35:

https://numpy.org/neps/nep-0035-array-creation-dispatch-with-array-function.html

Which added `like=` keyword argument to `np.array`, `np.asarray`,
`np.arange`, etc. as final.


The previous acceptance mail was here: 
https://mail.python.org/pipermail/numpy-discussion/2021-May/081761.html

But, since it may have flown under the radar.  Please don't hesitate to
voice any concerns!
We are planning to include this finalization in the NumPy 1.21 release.
So if you are worried about it, please make sure to voice that soon
since the release process for 1.21 started.


I had previously noted some possible concerns here:
https://github.com/numpy/numpy/issues/17075
but in the current version, the `like=` argument is strict about types
and will raise for `np.array(3, like=3)`.  With that limitation, most
of those points seem unproblematic.

Cheers,

Sebastian

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


Re: [Numpy-discussion] numpy histogram data

2021-06-07 Thread Keith Sloan
Thanks

Okay trying to understand the data being returned.
I have 

counts, bins = np.histogram(RedEllipticalMasses['Z_1'],bins=80)

If I print lengths I get
RedEllipticalMasses is 2514
bins = 81
and counts is 5
( It is 5 Arrays each of length 80)

Okay I can get centers with
centers = 0.5 * (bins[1:] + bins[:-1]

As you advised
But unclear how I would get their heights and why counts has 5 arrays ?



--
Sent from: http://numpy-discussion.10968.n7.nabble.com/
___
NumPy-Discussion mailing list
NumPy-Discussion@python.org
https://mail.python.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] Tensor Typing presentation and discussion on Wednesday! (As part of the NumPy Community Meeting)

2021-06-07 Thread Sebastian Berg
Hi all,

There will be a NumPy Community meeting Wednesday June 9th at
20:00 UTC.

This meeting will be dedicated to a presentation by Matthew and Pradeep
about typing arrays.

The title is:  "Better types for numerical computing - arrays generic
in dtype and shape"

Abstract: An overview of why more detailed types for arrays would be
awesome, the work being done to enable those types in PEP 646, and what
the future of this effort could look like.


If you are interested in typing and/or missed out on the Python typing
summit, this will be a perfect opportunity to join and discuss better
typing of NumPy arrays!


Details on how to join can be found in the usual meeting notes:

https://hackmd.io/76o-IxCjQX2mOXO_wwkcpg?both

Best wishes

Sebastian

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


Re: [Numpy-discussion] Best fit linear piecewise function?

2021-06-07 Thread Chris Barker
On Thu, Jun 3, 2021 at 4:13 AM Mark Bakker  wrote:

> My students are using this and seem to like it:
>
> https://jekel.me/piecewise_linear_fit_py/about.html
>

thanks -- that looks perfect!

-CHB



>
>
>> Date: Tue, 1 Jun 2021 17:22:52 -0700
>> From: Chris Barker 
>> To: Discussion of Numerical Python 
>> Subject: [Numpy-discussion] Best fit linear piecewise function?
>> Message-ID:
>> > i58wz0dl_292gvntmfrte88ik98h2nqt1...@mail.gmail.com>
>> Content-Type: text/plain; charset="utf-8"
>>
>> Do any of you know of code for finding an optimum linear piecewise fit to
>> a
>> set of points?
>>
>> Somethin like what is described in this article:
>>
>> https://www.hindawi.com/journals/mpe/2015/876862/
>>
>> At a glance, that looked just hard enough to code up that I'm hoping
>> someone has already done it :-)
>>
>> -CHB
>>
>>
>> --
>>
>> 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
>> -- next part --
>> An HTML attachment was scrubbed...
>> URL: <
>> https://mail.python.org/pipermail/numpy-discussion/attachments/20210601/fa6567d6/attachment-0001.html
>> >
>>
>>
>> ___
> NumPy-Discussion mailing list
> NumPy-Discussion@python.org
> https://mail.python.org/mailman/listinfo/numpy-discussion
>


-- 

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@python.org
https://mail.python.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Best fit linear piecewise function?

2021-06-07 Thread Chris Barker
On Thu, Jun 3, 2021 at 4:43 AM Klaus Zimmermann 
wrote:

> if you are interested in the 1d problem, you might also consider a
> spline fit of order 1, for example with scipy.interpolate, see [1].
>

hmm, yes, that should work -- I guess it didn't dawn on me because all
examples are higher order, but I'll check it out.

-CHB



> Cheers
> Klaus
>
>
> [1]
>
> https://docs.scipy.org/doc/scipy/reference/tutorial/interpolate.html#spline-interpolation-in-1-d-procedural-interpolate-splxxx
>
> On 03/06/2021 13:12, Mark Bakker wrote:
> > My students are using this and seem to like it:
> >
> > https://jekel.me/piecewise_linear_fit_py/about.html
> > 
> >
> >
> > Date: Tue, 1 Jun 2021 17:22:52 -0700
> > From: Chris Barker  > >
> > To: Discussion of Numerical Python  > >
> > Subject: [Numpy-discussion] Best fit linear piecewise function?
> > Message-ID:
> >
> >  > >
> > Content-Type: text/plain; charset="utf-8"
> >
> > Do any of you know of code for finding an optimum linear piecewise
> > fit to a
> > set of points?
> >
> > Somethin like what is described in this article:
> >
> > https://www.hindawi.com/journals/mpe/2015/876862/
> > 
> >
> > At a glance, that looked just hard enough to code up that I'm hoping
> > someone has already done it :-)
> >
> > -CHB
> >
> >
> > --
> >
> > 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 
> > -- next part --
> > An HTML attachment was scrubbed...
> > URL:
> > <
> https://mail.python.org/pipermail/numpy-discussion/attachments/20210601/fa6567d6/attachment-0001.html
> > <
> https://mail.python.org/pipermail/numpy-discussion/attachments/20210601/fa6567d6/attachment-0001.html
> >>
> >
> >
> >
> > ___
> > 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
>


-- 

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@python.org
https://mail.python.org/mailman/listinfo/numpy-discussion