배열

class Array(dtype: str, shape: list[int], stype: str, data: bytes)[소스]
class Array(ndarray: ndarray[Any, dtype[Any]])

기반 클래스: object

배열 유형.

A dataclass containing serialized data from an array-like or tensor-like object along with metadata about it. The class can be initialized in one of two ways:

  1. By specifying explicit values for dtype, shape, stype, and data.

  2. By providing a NumPy ndarray (via the ndarray argument).

In scenario (2), the dtype, shape, stype, and data are automatically derived from the input. In scenario (1), these fields must be specified manually.

매개변수:
  • dtype (Optional[str] (default: None)) – A string representing the data type of the serialized object (e.g. “float32”). Only required if you are not passing in a ndarray.

  • shape (Optional[list[int]] (default: None)) – A list representing the shape of the unserialized array-like object. Only required if you are not passing in a ndarray.

  • stype (Optional[str] (default: None)) – A string indicating the serialization mechanism used to generate the bytes in data from an array-like or tensor-like object. Only required if you are not passing in a ndarray.

  • data (Optional[bytes] (default: None)) – A buffer of bytes containing the data. Only required if you are not passing in a ndarray.

  • ndarray (Optional[NDArray] (default: None)) – A NumPy ndarray. If provided, the dtype, shape, stype, and data fields are derived automatically from it.

예제

Initializing by specifying all fields directly:

>>> arr1 = Array(
>>>     dtype="float32",
>>>     shape=[3, 3],
>>>     stype="numpy.ndarray",
>>>     data=b"serialized_data...",
>>> )

Initializing with a NumPy ndarray:

>>> import numpy as np
>>> arr2 = Array(np.random.randn(3, 3))

메소드

from_numpy_ndarray(ndarray)

NumPy에서 배열을 만듭니다.

numpy()

배열을 NumPy 배열로 반환합니다.

속성

dtype

shape

stype

data

classmethod from_numpy_ndarray(ndarray: ndarray[Any, dtype[Any]]) Array[소스]

NumPy에서 배열을 만듭니다.

numpy() ndarray[Any, dtype[Any]][소스]

배열을 NumPy 배열로 반환합니다.