Axes

class histpy.Axes(edges, labels=None, axis_scale=None)[source]

Bases: object

Holds a list of axes.

The operator Axes[key] return a subset of these. Key can be either the index or the label. If the key is a single index, a single Axis object will be returned

Parameters:
  • edges (array or list of arrays or Axis) – Definition of bin edges.

  • labels (array of str) – Optionally label the axes for easier indexing. Will override the labels of edges, if they are Axis objects

  • axis_scale (str or array) – Bin center mode e.g. “linear” or “log”. See Axis.axis_scale. If not an array, all axes will have this mode.

property ndim

Number of axes

label_to_index(key)[source]

Turn a key or list of keys, either indices or labels, into indices

Parameters:

key (int or str) – Index or label

Returns:

Index

Return type:

int

find_bin(*values)[source]

Return one or more indices corresponding to the bin this value or set of values correspond to.

You can pass either an array, or specified the values as different arguments. i.e. h.find_bin(x,y,z) = h.find_bin([x,y,z])

Multiple entries can be passed at once. e.g. h.find_bin([x0, x1, x2]), h.find_bin([x0, x1],[y0, y1],[z0, z1]), h.find_bin([[x0, x1],[y0, y1],[z0, z1]])

Parameters:

values (float or array) – Vaule or list of values. Either shape N or ndim x N, where N is the number of entries.

Returns:

Bin index

Return type:

int or tuple

interp_weights(*values)[source]

Get the bins and weights to linearly interpolate between bins. The bin contents are assigned to the center of the bin.

Parameters:

values (float or array) – Coordinates within the axes to interpolate.

Returns:

Bins and weights to use. Shaped (2^ndim, N). Bins is an array of tupples for multi-dimensional histograms.

Return type:

array of tuples of int, array of floats

expand_dims(a, axis)[source]

Insert new axes into a as appropiate to allow broadcasting with a histogram having these axes

broadcast(a, axis)[source]

Expand the dimensions and broadcast an array for a given set of axes such that it has the same dimensions as the histogram.

Parameters:
  • a (array) – Array to broadcast

  • axis (int or array) – Histogram axes correspond to the array axes.

expand_dict(axis_value, default=None)[source]

Convert pairs of axis:value to a list of length ndim.

Parameters:
  • axis_value (dict) – Dictionary with axis-value pairs (can be labels)

  • default – Default filling value for unspecified axes

Returns:

tuple