Skip to content

Commit 218bfd7

Browse files
committed
docs: use awk/arr
1 parent beff424 commit 218bfd7

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

README.md

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ This overview is based on the [documentation here](https://vector.readthedocs.io
2929
```python
3030
import vector
3131
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
3333
import numba as nb
3434
```
3535

@@ -38,8 +38,8 @@ import numba as nb
3838
The easiest way to create one or many vectors is with a helper function:
3939

4040
* `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`).
4343

4444
### Pure Python vectors
4545

@@ -113,22 +113,22 @@ and so on, for all combinations of azimuthal, longitudinal, and temporal coordin
113113

114114
```python
115115
# NumPy-like arguments (literally passed through to NumPy)
116-
vector.array([
116+
vector.arr([
117117
(1.1, 2.1), (1.2, 2.2), (1.3, 2.3), (1.4, 2.4), (1.5, 2.5)
118118
], dtype=[("x", float), ("y", float)])
119119

120120
# 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]})
122122

123123
# As with objects, the coordinate system and dimension is taken from the names of the fields.
124-
vector.array({
124+
vector.arr({
125125
"x": [1.1, 1.2, 1.3, 1.4, 1.5],
126126
"y": [2.1, 2.2, 2.3, 2.4, 2.5],
127127
"z": [3.1, 3.2, 3.3, 3.4, 3.5],
128128
"t": [4.1, 4.2, 4.3, 4.4, 4.5],
129129
})
130130

131-
vector.array({
131+
vector.arr({
132132
"pt": [1.1, 1.2, 1.3, 1.4, 1.5],
133133
"phi": [2.1, 2.2, 2.3, 2.4, 2.5],
134134
"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
153153
```
154154

155155

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.
157157

158158
Geometrical names are used in the dtype, even if momentum-synonyms are used in construction.
159159

160160

161161
```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]})
163163
```
164164

165165

166166
### Awkward Arrays of vectors
167167

168168
[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).
169169

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.
171171

172172

173173
```python
174-
vector.Array([
174+
vector.awk([
175175
[{"x": 1, "y": 1.1, "z": 0.1}, {"x": 2, "y": 2.2, "z": 0.2}],
176176
[],
177177
[{"x": 3, "y": 3.3, "z": 0.3}],
@@ -201,7 +201,7 @@ ak.Array([
201201

202202

203203

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.
205205

206206
## Vector properties
207207

@@ -251,13 +251,13 @@ Here's the key thing: _arrays of vectors return arrays of coordinates_.
251251

252252

253253
```python
254-
vector.array({
254+
vector.arr({
255255
"x": [1.0, 2.0, 3.0, 4.0, 5.0],
256256
"y": [1.1, 2.2, 3.3, 4.4, 5.5],
257257
"z": [0.1, 0.2, 0.3, 0.4, 0.5],
258258
}).theta
259259

260-
vector.Array([
260+
vector.awk([
261261
[{"x": 1, "y": 1.1, "z": 0.1}, {"x": 2, "y": 2.2, "z": 0.2}],
262262
[],
263263
[{"x": 3, "y": 3.3, "z": 0.3}],
@@ -275,7 +275,7 @@ array.shape
275275
array.pt.shape
276276

277277
# 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)])
279279

280280
# Get the transverse momentum of each one, in the same nested structure.
281281
array.pt
@@ -296,19 +296,19 @@ vector.obj(x=3, y=4).rotateZ(0.1)
296296
vector.obj(rho=5, phi=0.4).rotateZ(0.1)
297297

298298
# 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))
300300

301301
# 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])))
303303

304304
# 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))
306306

307307
# 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]))
309309

310310
# 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]]))
312312
```
313313

314314

@@ -369,10 +369,10 @@ The vectors can be from different backends. Normal rules for broadcasting Python
369369

370370

371371
```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)
373373

374374
(
375-
vector.Array([ # an Awkward Array of vectors
375+
vector.awk([ # an Awkward Array of vectors
376376
[{"x": 1, "y": 1.1}, {"x": 2, "y": 2.2}],
377377
[],
378378
[{"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
382382
)
383383

384384
(
385-
vector.Array([ # an Awkward Array of vectors
385+
vector.awk([ # an Awkward Array of vectors
386386
[{"x": 1, "y": 1.1}, {"x": 2, "y": 2.2}],
387387
[],
388388
[{"x": 3, "y": 3.3}],
389389
[{"x": 4, "y": 4.4}, {"x": 5, "y": 5.5}],
390390
])
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
392392
)
393393
```
394394

@@ -533,7 +533,7 @@ Although this demonstrates that Numba can manipulate vector objects, there is no
533533

534534
```python
535535
# 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)])
537537

538538
@nb.njit
539539
def compute_masses(array):

0 commit comments

Comments
 (0)