Closed kreczko closed 1 year ago
The data are there, with full precision, but ak.Array.__str__
minimizes the printed resolution to save screen space for all of the brackets and record key names that may be in complex data types.
>>> import numpy as np
>>> import awkward as ak
>>> import vector
>>> data = dict(
... px=ak.Array([[10., 20., 30.], [50., 60.]]),
... py=ak.Array([[20., 30., 40.], [60., 70.]]),
... pz=ak.Array([[30., 40., 50.], [70., 80.]]),
... )
>>> mass = 90.0
>>> data["energy"] = np.sqrt(data["px"] ** 2 + data["py"] ** 2 + data["pz"] ** 2 + mass ** 2)
>>> p4 = vector.zip(
... {
... "px": data["px"],
... "py": data["py"],
... "pz": data["pz"],
... "energy": data["energy"],
... }
... )
>>> combinations = ak.combinations(p4, 2, fields=["p1", "p2"])
>>> masses = (combinations["p1"] + combinations["p2"]).mass # same as .tau
So
>>> masses
<Array [[181, 183, 181], [180]] type='2 * var * float64'>
but
>>> masses.to_list()
[[180.67940751580096, 182.51419683759175, 180.57777240589775], [180.330167894841]]
or even
>>> masses - 180
<Array [[0.679, 2.51, 0.578], [0.33]] type='2 * var * float64'>
NumPy also truncates by default, but not as much.
>>> ak.to_numpy(ak.fill_none(ak.pad_none(masses, 3), 0))
array([[180.67940752, 182.51419684, 180.57777241],
[180.33016789, 0. , 0. ]])
Between Awkward Array, NumPy, and Python, only Python gives you the full precision so that if you copy the string representation, you can make a new object with the same precision (exactly the same). Actually, this is sometimes considered a problem because newcomers to programming can be confused by
>>> 0.1 + 0.1 + 0.1
0.30000000000000004
(which you don't see with np.array([[0.1, 0.1, 0.1]]).sum(axis=1)
or ak.sum([[0.1, 0.1, 0.1]], axis=1)
).
Vector Version
1.0.0
Python Version
Python 3.10.4
OS / Environment
Ubuntu 22.04.2 LTS
Describe the bug
There is a discrepancy (or I am doing something very wrong) when calculating the mass of a 4-vector on arrays vs individual objects.
Given the example below, I get the results:
[[181, 183, 181], [180]]
[180.67940751580096, 182.51419683759175, 180.57777240589775, 180.330167894841]
The type for the vector approach looks correct:
type='2 * var * float64'>
Example
EDIT: Additional example
This provides same output as the
invariant_mass
function (in case there are questions aboutnp
use):Any additional but relevant log output
Example code should output