'Convert numpy array into Ray dataset

What is the correct way to convert numpy array into ray's dataset? I tried the following, but its not working.

import numpy as np
arr = np.array([[1.9, 1.0, 1.1, 0.9],
         [1.8, 1.0, 1.1, 0.9],
         [1.7, 1.0, 1.2, 0.8],
         [1.6, 1.0, 1.3, 0.9],
         [1.5, 1.0, 1.4, 0.9]])
print(arr)
ds=ray.data.from_numpy(arr)
ds.show(10)

Numpy array is not stored in ray dataset correctly. It is saved as

{'value': array(1.9)}
{'value': array(1.)}
{'value': array(1.1)}
{'value': array(0.9)}
{'value': array(1.8)}
{'value': array(1.)}
{'value': array(1.1)}
{'value': array(0.9)}
{'value': array(1.7)}
{'value': array(1.)}

Thanks in advance



Solution 1:[1]

When using Ray 1.11.0, you should be able to return the correct structure of your NumPy array by passing in [arr] rather than arr.

ds = ray.data.from_numpy([arr])

When doing the above, ds.show(10) should return:

{'value': array([1.9, 1. , 1.1, 0.9])}
{'value': array([1.8, 1. , 1.1, 0.9])}
{'value': array([1.7, 1. , 1.2, 0.8])}
{'value': array([1.6, 1. , 1.3, 0.9])}
{'value': array([1.5, 1. , 1.4, 0.9])}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 dynamicwebpaige