---
title: 函数：ptr_to_numpy
description: "该接口即将废弃，建议使用acl.util.ptr_to_bytes接口。"
url: https://www.hiascend.com/document/detail/zh/canncommercial/latest/API/runtimeapi/aclpythondevg_01_0054.html
sourcePath: /source/zh/canncommercial/900/API/runtimeapi/aclpythondevg_01_0054.html
indexId: 82762f298c0749b61edaf950ee67c59a04ec6398c19739b8efba5f6fd062e3da71
---
# 函数：ptr_to_numpy

该接口即将废弃，建议使用acl.util.ptr_to_bytes接口。


| C函数原型 | 无 |
| --- | --- |
| Python函数 | output = acl.util.ptr\_to\_numpy(ptr, shape, type) |
| 函数功能 | 将指针地址数据转换为numpy数组，可以使Python代码直接访问。 |
| 输入说明 | ptr：int，C语言中的指针地址，是能够访问的数据的首地址。 shape：tuple，需要构造的numpy的Shape。 type：int，表示ptr中数据的数据类型。 下面举例一些常用的类型（未列出类型详见Numpy手册(https://numpy.org/doc/stable/user/c\-info.html\#)，NumPy C\-API中的数据类型API，以下列出类型以手册中数据为准）： 0：NPY\_BOOL 1：NPY\_BYTE，NPY\_INT8 2：NPY\_UINT8 3：NPY\_SHORT，NPY\_INT16 4：NPY\_USHORT，NPY\_UINT16 5：NPY\_INT，NPY\_INT32 6：NPY\_UINT，NPY\_UINT32 7：NPY\_INT64 8：NPY\_UINT64 9：NPY\_LONGLONG 10：NPY\_ULONGLONG 11：NPY\_FLOAT32 12：NPY\_DOUBLE 23：NPY\_HALF，NPY\_FLOAT16 |
| 返回值说明 | output：numpy类型。 |
| 约束说明 | 无 |
| 注意事项 | 修改示例如下： np\_arr\_out = acl.util.ptr\_to\_numpy(host\_ptr, np\_arr\_in.shape, NPY\_INT32) 修改后使用： bytes\_out = acl.util.ptr\_to\_bytes(ptr, size) np\_arr\_out = np.frombuffer(bytes\_out, dtype=np.int32).reshape(np\_arr\_in.shape) 若要继续使用该接口，需要运行环境为python ≥ 3.8且numpy ≥ 1.22.0。 |
