The N-Dimensional Array Object【免费下载链接】asnumpy-docs项目地址: https://gitcode.com/cann/asnumpy-docs::: info This API section currently keeps a curated subset of representative APIs. Additional API documentation is temporarily hidden while the AsNumpy frontend and documentation system are still undergoing major restructuring, and it will be expanded after the frontend stabilizes. This document is for reference only. :::Constructorasnumpy.ndarrayasnumpy.ndarray(shape: Sequence[int], dtype: np.dtype) - NoneRepresent a multi-dimensional array on the device.This class encapsulates a C backend array and provides a Python interface for performing array operations directly on the accelerator (NPU). Users interact with device-resident arrays through this class, enabling efficient computations while maintaining a NumPy-like interface.::: tip This class is typically not created directly. Use array creation routines such asasnumpy.zeros,asnumpy.ones, orasnumpy.ndarray.from_numpyto construct arrays on the device. :::asnumpy.ndarray.from_numpyasnumpy.ndarray.from_numpy(host_data: numpy.ndarray) - ndarrayCreate an asnumpy.ndarray from a numpy.ndarray.This function copies the data from the host (CPU) to the device (NPU).Argumentshost_data(numpy.ndarray): The input NumPy array.Returnsasnumpy.ndarray: A new array on the device containing the same data ashost_data.Examples import numpy as np import asnumpy as ap x_cpu np.array([1, 2, 3]) x_npu ap.ndarray.from_numpy(x_cpu) type(x_cpu) class numpy.ndarray type(x_npu) class asnumpy.ndarrayPropertiesasnumpy.ndarray.shapeasnumpy.ndarray.shape - tupleReturns the dimensions of the array as a tuple of integers.Returnstuple: The shape of the array.See Alsonumpy.ndarray.shapeasnumpy.ndarray.dtypeasnumpy.ndarray.dtype - np.dtypeReturns the data type information for elements stored in the array.Returnsnumpy.dtype: The data type of the array elements.See Alsonumpy.ndarray.dtypeasnumpy.ndarray.acl_dtypeasnumpy.ndarray.acl_dtype - intInternal ACL data type identifier.Returnsint: The ACL data type enum value.Methodsasnumpy.ndarray.to_numpyasnumpy.ndarray.to_numpy() - numpy.ndarrayReturn a copy of the array data as a numpy.ndarray.This function copies the data from the device (NPU) to the host (CPU).Returnsnumpy.ndarray: A NumPy array containing the data from the device array.Examples import asnumpy as ap x_npu ap.zeros(3) x_cpu x_npu.to_numpy() type(x_cpu) class numpy.ndarray【免费下载链接】asnumpy-docs项目地址: https://gitcode.com/cann/asnumpy-docs创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考