Page 21 of 21

Re: Python tricks

Posted: July 24th, 2025, 9:40 am
by Cuchulainn
import boost_histogram as bh
import numpy as np
import matplotlib as plt



# Compose axis however you like; this is a 2D histogram
hist = bh.Histogram(bh.axis.Regular(2, 0, 1), bh.axis.Regular(4, 0.0, 1.0))

# Filling can be done with arrays, one per dimension
hist.fill([0.3, 0.5, 0.2], [0.1, 0.4, 0.9])

# NumPy array view into histogram counts, no overflow bins
counts = hist.view()
print(counts)
Tags,
similar output?

1989
Image
1981

Image

Re: Python tricks

Posted: October 11th, 2025, 9:34 am
by tags
Any comments on the brand new Python 3.14 e.g. no-GIL and then?

Re: Python tricks

Posted: October 11th, 2025, 9:57 am
by tags
import boost_histogram as bh
import numpy as np
import matplotlib as plt



# Compose axis however you like; this is a 2D histogram
hist = bh.Histogram(bh.axis.Regular(2, 0, 1), bh.axis.Regular(4, 0.0, 1.0))

# Filling can be done with arrays, one per dimension
hist.fill([0.3, 0.5, 0.2], [0.1, 0.4, 0.9])

# NumPy array view into histogram counts, no overflow bins
counts = hist.view()
print(counts)
Tags,
similar output?

1989
Image
1981

Image


import numpy as np

# Define bin edges
x_bins = np.linspace(0, 1, 3)
y_bins = np.linspace(0, 1, 5)

# Sample data points
x_data = np.array([0.3, 0.5, 0.2])
y_data = np.array([0.1, 0.4, 0.9])

# Compute 2D histogram
hist, x_edges, y_edges = np.histogram2d(x_data, y_data, bins=[x_bins, y_bins])

# Print result
print(hist)
mere numpy version
boost_histogram has some cool features. thanks for mentioning it.