mindspore.frombuffer

View Source On Gitee
mindspore.frombuffer(buffer: object, dtype: object, count: int = - 1, offset: int = 0) object

Create a 1-D tensor from an object implements the buffer interface. The returned tensor shares the same memory space as the buffer.

Parameters
  • buffer (-) –

  • dtype (-) –

  • count (-) – -1 .

  • offset (-) – 0 .

Returns

Tensor, a 1-D tensor containing the data from the buffer.

Raises
  • - RuntimeError - If count is a negative number less than -1.

  • - RuntimeError - If the buffer length is less than or equal to 0, or if count is 0.

  • - RuntimeError - If offset is not within the range [0, buffer length - 1].

  • - RuntimeError - When count is -1, if (buffer length - offset) is not divisible by the element size.

  • - RuntimeError - If the remaining buffer size after offset is insufficient to accommodate the requested number of elements.

Examples

>>> import mindspore
>>> data = bytearray([1, 2, 3, 4, 5, 6])
>>> tensor = mindspore.frombuffer(data, dtype=mindspore.uint8)
>>> print(tensor)
[1 2 3 4 5 6]