Skip to content

Instantly share code, notes, and snippets.

View jpivarski's full-sized avatar

Jim Pivarski jpivarski

  • Princeton, IRIS-HEP, PyHEP, Scikit-HEP
View GitHub Profile
@jpivarski
jpivarski / draft-lazy.py
Last active October 28, 2024 20:12
Draft of lazy layouts in Awkward v2
from typing import Callable
import awkward as ak
class LazyMixin:
def __init__(
self,
materialize: Callable[[], ak.contents.Content],
length: ak._nplikes.shape.ShapeItem,
@jpivarski
jpivarski / from-stackoverflow.md
Created October 15, 2024 23:34
Curated Awkward/Uproot questions from StackOverflow

-- Question -----------------------------------------------

I am trying to rebin my hist objects from linear bins to log(x) bins. I see on the UHI read the docs on indexing (https://uhi.readthedocs.io/en/latest/indexing.html#) that it is possible to linear rebin with h == h[::rebin(2)], but this gives all bins the same width still. Is it possible to rebin with user defined bin edges? In this case, I wanted log(x) bins. If it is not possible, I am also thinking about making a new hist object that meets the log(x) bins by slicing the original histogram in a loop, each loop being each bin edges.

-- Answer ------------

Linear to log won't work because edges can't move. Ultimately variable space rebinning boils down to "map x bins into one" over and over, where x changes. The final set of bin edges will always be a subset of the original bin edges. You can make them sort-of log space with rounding to the nearest linear bin edge (but I'd highly recommend waiting for the next release of boost-histogram, as ful

@jpivarski
jpivarski / autodiff-with-nothing-but-numpy.ipynb
Created August 6, 2024 16:17
Autodiff with nothing but NumPy
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jpivarski
jpivarski / Neural_net_warping_tutorial.ipynb
Created July 19, 2024 18:00 — forked from roycoding/Neural_net_warping_tutorial.ipynb
Feature space warping by neural networks
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jpivarski
jpivarski / orbitty.py
Last active May 3, 2024 21:04
Package to demonstrate testing
import numpy as np
class System:
G = 3
min_distance = 0.1
@classmethod
def random(cls, num_particles, num_dimensions, mass_mean, mass_width, x_width, p_width):
m = np.random.gamma(mass_mean / mass_width, mass_width, num_particles)
x = np.random.normal(0, x_width, (num_particles, num_dimensions))
@jpivarski
jpivarski / python-skills-survey-list.ipynb
Created April 23, 2024 02:00
python-skills-survey-list
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jpivarski
jpivarski / extra-stuff-2.ipynb
Last active April 3, 2024 02:17
Plan for SciPy Teen Track
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jpivarski
jpivarski / computer-breaking-probability.ipynb
Last active November 16, 2023 17:28
Computer breaking probability
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.