@@ -29,7 +29,7 @@ This overview is based on the [documentation here](https://vector.readthedocs.io
29
29
``` python
30
30
import vector
31
31
import numpy as np
32
- import awkward as ak # at least version 1.2.0rc5
32
+ import awkward as ak # at least version 1.2.0
33
33
import numba as nb
34
34
```
35
35
@@ -38,8 +38,8 @@ import numba as nb
38
38
The easiest way to create one or many vectors is with a helper function:
39
39
40
40
* ` vector.obj ` to make a pure Python vector object,
41
- * ` vector.array ` to make a NumPy array of vectors (lowercase, like ` np.array ` ),
42
- * ` vector.Array ` to make an Awkward Array of vectors (uppercase, like ` ak.Array ` ).
41
+ * ` vector.arr ` to make a NumPy array of vectors (lowercase, like ` np.array ` ),
42
+ * ` vector.awk ` to make an Awkward Array of vectors (uppercase, like ` ak.Array ` ).
43
43
44
44
### Pure Python vectors
45
45
@@ -113,22 +113,22 @@ and so on, for all combinations of azimuthal, longitudinal, and temporal coordin
113
113
114
114
``` python
115
115
# NumPy-like arguments (literally passed through to NumPy)
116
- vector.array ([
116
+ vector.arr ([
117
117
(1.1 , 2.1 ), (1.2 , 2.2 ), (1.3 , 2.3 ), (1.4 , 2.4 ), (1.5 , 2.5 )
118
118
], dtype = [(" x" , float ), (" y" , float )])
119
119
120
120
# Pandas-like arguments (dict from names to column arrays)
121
- vector.array ({" x" : [1.1 , 1.2 , 1.3 , 1.4 , 1.5 ], " y" : [2.1 , 2.2 , 2.3 , 2.4 , 2.5 ]})
121
+ vector.arr ({" x" : [1.1 , 1.2 , 1.3 , 1.4 , 1.5 ], " y" : [2.1 , 2.2 , 2.3 , 2.4 , 2.5 ]})
122
122
123
123
# As with objects, the coordinate system and dimension is taken from the names of the fields.
124
- vector.array ({
124
+ vector.arr ({
125
125
" x" : [1.1 , 1.2 , 1.3 , 1.4 , 1.5 ],
126
126
" y" : [2.1 , 2.2 , 2.3 , 2.4 , 2.5 ],
127
127
" z" : [3.1 , 3.2 , 3.3 , 3.4 , 3.5 ],
128
128
" t" : [4.1 , 4.2 , 4.3 , 4.4 , 4.5 ],
129
129
})
130
130
131
- vector.array ({
131
+ vector.arr ({
132
132
" pt" : [1.1 , 1.2 , 1.3 , 1.4 , 1.5 ],
133
133
" phi" : [2.1 , 2.2 , 2.3 , 2.4 , 2.5 ],
134
134
" eta" : [3.1 , 3.2 , 3.3 , 3.4 , 3.5 ],
@@ -153,25 +153,25 @@ np.arange(0, 24, 0.1).view([("x", float), ("y", float), ("z", float), ("t", floa
153
153
```
154
154
155
155
156
- All of the keyword arguments and rules that apply to ` vector.obj ` construction apply to ` vector.array ` dtypes.
156
+ All of the keyword arguments and rules that apply to ` vector.obj ` construction apply to ` vector.arr ` dtypes.
157
157
158
158
Geometrical names are used in the dtype, even if momentum-synonyms are used in construction.
159
159
160
160
161
161
``` python
162
- vector.array ({" px" : [1 , 2 , 3 , 4 ], " py" : [1.1 , 2.2 , 3.3 , 4.4 ], " pz" : [0.1 , 0.2 , 0.3 , 0.4 ]})
162
+ vector.arr ({" px" : [1 , 2 , 3 , 4 ], " py" : [1.1 , 2.2 , 3.3 , 4.4 ], " pz" : [0.1 , 0.2 , 0.3 , 0.4 ]})
163
163
```
164
164
165
165
166
166
### Awkward Arrays of vectors
167
167
168
168
[ Awkward Arrays] ( https://awkward-array.org/ ) are arrays with more complex data structures than NumPy allows, such as variable-length lists, nested records, missing and even heterogeneous data (multiple data types: use sparingly).
169
169
170
- The ` vector.Array ` function behaves exactly like the [ ak.Array] ( https://awkward-array.readthedocs.io/en/latest/_auto/ak.Array.html ) constructor, except that it makes arrays of vectors.
170
+ The ` vector.awk ` function behaves exactly like the [ ak.Array] ( https://awkward-array.readthedocs.io/en/latest/_auto/ak.Array.html ) constructor, except that it makes arrays of vectors.
171
171
172
172
173
173
``` python
174
- vector.Array ([
174
+ vector.awk ([
175
175
[{" x" : 1 , " y" : 1.1 , " z" : 0.1 }, {" x" : 2 , " y" : 2.2 , " z" : 0.2 }],
176
176
[],
177
177
[{" x" : 3 , " y" : 3.3 , " z" : 0.3 }],
@@ -201,7 +201,7 @@ ak.Array([
201
201
202
202
203
203
204
- All of the keyword arguments and rules that apply to ` vector.obj ` construction apply to ` vector.Array ` field names.
204
+ All of the keyword arguments and rules that apply to ` vector.obj ` construction apply to ` vector.awk ` field names.
205
205
206
206
## Vector properties
207
207
@@ -251,13 +251,13 @@ Here's the key thing: _arrays of vectors return arrays of coordinates_.
251
251
252
252
253
253
``` python
254
- vector.array ({
254
+ vector.arr ({
255
255
" x" : [1.0 , 2.0 , 3.0 , 4.0 , 5.0 ],
256
256
" y" : [1.1 , 2.2 , 3.3 , 4.4 , 5.5 ],
257
257
" z" : [0.1 , 0.2 , 0.3 , 0.4 , 0.5 ],
258
258
}).theta
259
259
260
- vector.Array ([
260
+ vector.awk ([
261
261
[{" x" : 1 , " y" : 1.1 , " z" : 0.1 }, {" x" : 2 , " y" : 2.2 , " z" : 0.2 }],
262
262
[],
263
263
[{" x" : 3 , " y" : 3.3 , " z" : 0.3 }],
@@ -275,7 +275,7 @@ array.shape
275
275
array.pt.shape
276
276
277
277
# Make a large, random Awkward Array of 3D momentum vectors.
278
- array = vector.Array ([[{x: np.random.normal(0 , 1 ) for x in (" px" , " py" , " pz" )} for inner in range (np.random.poisson(1.5 ))] for outer in range (50 )])
278
+ array = vector.awk ([[{x: np.random.normal(0 , 1 ) for x in (" px" , " py" , " pz" )} for inner in range (np.random.poisson(1.5 ))] for outer in range (50 )])
279
279
280
280
# Get the transverse momentum of each one, in the same nested structure.
281
281
array.pt
@@ -296,19 +296,19 @@ vector.obj(x=3, y=4).rotateZ(0.1)
296
296
vector.obj(rho = 5 , phi = 0.4 ).rotateZ(0.1 )
297
297
298
298
# Broadcasts a scalar rotation angle of 0.5 to all elements of the NumPy array.
299
- print (vector.array ({" rho" : [1 , 2 , 3 , 4 , 5 ], " phi" : [0.1 , 0.2 , 0.3 , 0.4 , 0.5 ]}).rotateZ(0.5 ))
299
+ print (vector.arr ({" rho" : [1 , 2 , 3 , 4 , 5 ], " phi" : [0.1 , 0.2 , 0.3 , 0.4 , 0.5 ]}).rotateZ(0.5 ))
300
300
301
301
# Matches each rotation angle to an element of the NumPy array.
302
- print (vector.array ({" rho" : [1 , 2 , 3 , 4 , 5 ], " phi" : [0.1 , 0.2 , 0.3 , 0.4 , 0.5 ]}).rotateZ(np.array([0.1 , 0.2 , 0.3 , 0.4 , 0.5 ])))
302
+ print (vector.arr ({" rho" : [1 , 2 , 3 , 4 , 5 ], " phi" : [0.1 , 0.2 , 0.3 , 0.4 , 0.5 ]}).rotateZ(np.array([0.1 , 0.2 , 0.3 , 0.4 , 0.5 ])))
303
303
304
304
# Broadcasts a scalar rotation angle of 0.5 to all elements of the Awkward Array.
305
- print (vector.Array ([[{" rho" : 1 , " phi" : 0.1 }, {" rho" : 2 , " phi" : 0.2 }], [], [{" rho" : 3 , " phi" : 0.3 }]]).rotateZ(0.5 ))
305
+ print (vector.awk ([[{" rho" : 1 , " phi" : 0.1 }, {" rho" : 2 , " phi" : 0.2 }], [], [{" rho" : 3 , " phi" : 0.3 }]]).rotateZ(0.5 ))
306
306
307
307
# Broadcasts a rotation angle of 0.1 to both elements of the first list, 0.2 to the empty list, and 0.3 to the only element of the last list.
308
- print (vector.Array ([[{" rho" : 1 , " phi" : 0.1 }, {" rho" : 2 , " phi" : 0.2 }], [], [{" rho" : 3 , " phi" : 0.3 }]]).rotateZ([0.1 , 0.2 , 0.3 ]))
308
+ print (vector.awk ([[{" rho" : 1 , " phi" : 0.1 }, {" rho" : 2 , " phi" : 0.2 }], [], [{" rho" : 3 , " phi" : 0.3 }]]).rotateZ([0.1 , 0.2 , 0.3 ]))
309
309
310
310
# Matches each rotation angle to an element of the Awkward Array.
311
- print (vector.Array ([[{" rho" : 1 , " phi" : 0.1 }, {" rho" : 2 , " phi" : 0.2 }], [], [{" rho" : 3 , " phi" : 0.3 }]]).rotateZ([[0.1 , 0.2 ], [], [0.3 ]]))
311
+ print (vector.awk ([[{" rho" : 1 , " phi" : 0.1 }, {" rho" : 2 , " phi" : 0.2 }], [], [{" rho" : 3 , " phi" : 0.3 }]]).rotateZ([[0.1 , 0.2 ], [], [0.3 ]]))
312
312
```
313
313
314
314
@@ -369,10 +369,10 @@ The vectors can be from different backends. Normal rules for broadcasting Python
369
369
370
370
371
371
``` python
372
- vector.array ({" x" : [1 , 2 , 3 , 4 , 5 ], " y" : [0.1 , 0.2 , 0.3 , 0.4 , 0.5 ]}) + vector.obj(x = 10 , y = 5 )
372
+ vector.arr ({" x" : [1 , 2 , 3 , 4 , 5 ], " y" : [0.1 , 0.2 , 0.3 , 0.4 , 0.5 ]}) + vector.obj(x = 10 , y = 5 )
373
373
374
374
(
375
- vector.Array ([ # an Awkward Array of vectors
375
+ vector.awk ([ # an Awkward Array of vectors
376
376
[{" x" : 1 , " y" : 1.1 }, {" x" : 2 , " y" : 2.2 }],
377
377
[],
378
378
[{" x" : 3 , " y" : 3.3 }],
@@ -382,13 +382,13 @@ vector.array({"x": [1, 2, 3, 4, 5], "y": [0.1, 0.2, 0.3, 0.4, 0.5]}) + vector.ob
382
382
)
383
383
384
384
(
385
- vector.Array ([ # an Awkward Array of vectors
385
+ vector.awk ([ # an Awkward Array of vectors
386
386
[{" x" : 1 , " y" : 1.1 }, {" x" : 2 , " y" : 2.2 }],
387
387
[],
388
388
[{" x" : 3 , " y" : 3.3 }],
389
389
[{" x" : 4 , " y" : 4.4 }, {" x" : 5 , " y" : 5.5 }],
390
390
])
391
- + vector.array ({" x" : [4 , 3 , 2 , 1 ], " y" : [0.1 , 0.1 , 0.1 , 0.1 ]}) # and a NumPy array of vectors
391
+ + vector.arr ({" x" : [4 , 3 , 2 , 1 ], " y" : [0.1 , 0.1 , 0.1 , 0.1 ]}) # and a NumPy array of vectors
392
392
)
393
393
```
394
394
@@ -533,7 +533,7 @@ Although this demonstrates that Numba can manipulate vector objects, there is no
533
533
534
534
``` python
535
535
# This is still not a large number. You want millions.
536
- array = vector.Array ([[dict ({x: np.random.normal(0 , 1 ) for x in (" px" , " py" , " pz" )}, E = np.random.normal(10 , 1 )) for inner in range (np.random.poisson(1.5 ))] for outer in range (50 )])
536
+ array = vector.awk ([[dict ({x: np.random.normal(0 , 1 ) for x in (" px" , " py" , " pz" )}, E = np.random.normal(10 , 1 )) for inner in range (np.random.poisson(1.5 ))] for outer in range (50 )])
537
537
538
538
@nb.njit
539
539
def compute_masses (array ):
0 commit comments