/
ak_from_numpy.py
55 lines (49 loc) · 2.23 KB
/
ak_from_numpy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# BSD 3-Clause License; see https://github.com/scikit-hep/awkward-1.0/blob/main/LICENSE
__all__ = ("from_numpy",)
import awkward as ak
from awkward._layout import from_arraylib, wrap_layout
def from_numpy(
array, *, regulararray=False, recordarray=True, highlevel=True, behavior=None
):
"""
Args:
array (np.ndarray): The NumPy array to convert into an Awkward Array.
This array can be a np.ma.MaskedArray.
regulararray (bool): If True and the array is multidimensional,
the dimensions are represented by nested #ak.contents.RegularArray
nodes; if False and the array is multidimensional, the dimensions
are represented by a multivalued #ak.contents.NumpyArray.shape.
If the array is one-dimensional, this has no effect.
recordarray (bool): If True and the array is a NumPy structured array
(dtype.names is not None), the fields are represented by an
#ak.contents.RecordArray; if False and the array is a structured
array, the structure is left in the #ak.contents.NumpyArray `format`,
which some functions do not recognize.
highlevel (bool): If True, return an #ak.Array; otherwise, return
a low-level #ak.contents.Content subclass.
behavior (None or dict): Custom #ak.behavior for the output array, if
high-level.
Converts a NumPy array into an Awkward Array.
The resulting layout can only involve the following #ak.contents.Content types:
* #ak.contents.NumpyArray
* #ak.contents.ByteMaskedArray or #ak.contents.UnmaskedArray if the
`array` is an np.ma.MaskedArray.
* #ak.contents.RegularArray if `regulararray=True`.
* #ak.contents.RecordArray if `recordarray=True`.
See also #ak.to_numpy and #ak.from_cupy.
"""
with ak._errors.OperationErrorContext(
"ak.from_numpy",
{
"array": array,
"regulararray": regulararray,
"recordarray": recordarray,
"highlevel": highlevel,
"behavior": behavior,
},
):
return wrap_layout(
from_arraylib(array, regulararray, recordarray),
highlevel=highlevel,
behavior=behavior,
)