to_table
The to_table
method creates a new table from a NumPy NDArray.
Syntax
to_table(np_array: numpy.ndarray, cols: List[str]) -> Table
Parameters
Parameter | Type | Description |
---|---|---|
table | Table | The source table to convert to a |
cols | List[str] | Defines the names of the columns in the resulting table. This parameter must have exactly as many column names as there are columns in the source NumPy NDArray. |
Returns
A Deephaven Table from the given NumPy NDArray and the column names.
Examples
In the following example, we create a NumPy NDArray and convert it to a Deephaven table using to_table
.
import numpy as np
from deephaven.numpy import to_table
source = np.array([[0, 1, 2], [3, 4, 5]])
result = to_table(source, cols=["col1", "col2", "col3"])
- result
In many cases, NumPy arrays are too large to manually enumerate all of the column names. In such cases, you may prefer to set column names programmatically, like so:
import numpy as np
from deephaven.numpy import to_table
source = np.arange(10000).reshape(100, 100)
# programatically name columns
result = to_table(source, cols=[f"X{i}" for i in range(source.shape[1])])
- result