MCPcopy
hub / github.com/ray-project/ray / from_numpy

Function from_numpy

python/ray/data/read_api.py:3508–3551  ·  view source on GitHub ↗

Creates a :class:`~ray.data.Dataset` from a list of NumPy ndarrays. The column name defaults to "data". Examples: >>> import numpy as np >>> import ray >>> arr = np.array([1]) >>> ray.data.from_numpy(arr) # doctest: +ELLIPSIS shape: (1, 1) ╭

(ndarrays: Union[np.ndarray, List[np.ndarray]])

Source from the content-addressed store, hash-verified

3506
3507@PublicAPI
3508def from_numpy(ndarrays: Union[np.ndarray, List[np.ndarray]]) -> MaterializedDataset:
3509 """Creates a :class:`~ray.data.Dataset` from a list of NumPy ndarrays.
3510
3511 The column name defaults to "data".
3512
3513 Examples:
3514 >>> import numpy as np
3515 >>> import ray
3516 >>> arr = np.array([1])
3517 >>> ray.data.from_numpy(arr) # doctest: +ELLIPSIS
3518 shape: (1, 1)
3519 ╭───────╮
3520 │ data │
3521 │ --- │
3522 │ int64 │
3523 ╞═══════╡
3524 │ 1 │
3525 ╰───────╯
3526 (Showing 1 of 1 rows)
3527
3528 Create a Ray Dataset from a list of NumPy arrays.
3529
3530 >>> ray.data.from_numpy([arr, arr]) # doctest: +ELLIPSIS
3531 shape: (2, 1)
3532 ╭───────╮
3533 │ data │
3534 │ --- │
3535 │ int64 │
3536 ╞═══════╡
3537 │ 1 │
3538 │ 1 │
3539 ╰───────╯
3540 (Showing 2 of 2 rows)
3541
3542 Args:
3543 ndarrays: A NumPy ndarray or a list of NumPy ndarrays.
3544
3545 Returns:
3546 :class:`~ray.data.Dataset` holding data from the given ndarrays.
3547 """
3548 if isinstance(ndarrays, np.ndarray):
3549 ndarrays = [ndarrays]
3550
3551 return from_numpy_refs([ray.put(ndarray) for ndarray in ndarrays])
3552
3553
3554@DeveloperAPI

Callers

nothing calls this directly

Calls 2

from_numpy_refsFunction · 0.85
putMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…