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

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


| C函数原型 | 无 |
| --- | --- |
| Python函数 | ptr, data\_out = acl.util.numpy\_contiguous\_to\_ptr(data\_in) |
| 函数功能 | 获取numpy.ndarray数组的内存数据指针地址。 若传入的numpy.ndarray数组在内存上是非行连续的，则先将其内存转为行连续，然后再获取转换后的numpy.ndarray数组转换成为内存数据指针地址。 |
| 输入说明 | data\_in：numpy类型数据。 |
| 返回值说明 | ptr：int，可以被C语言访问的数据。 data\_out：numpy类型数据，若传入的numpy数组“data\_in”内存非行连续，则返回值“data\_out”即为其内存转为行连续后的numpy数组。 |
| 约束说明 | 访问的是int类型的数据，需要将numpy.ndarray对象的内存数据指针地址转换为int。 |
| 注意事项 | 修改示例如下： np\_ptr, data\_out = acl.util.numpy\_contiguous\_to\_ptr(np\_arr\_in) 修改后使用： bytes\_in = np\_arr\_in.tobytes() bytes\_ptr = acl.util.bytes\_to\_ptr(bytes\_in) 若要继续使用该接口，需要运行环境为python ≥ 3.8且numpy ≥ 1.22.0。 使用本函数返回的指针地址前，需要确保传入的numpy.ndarray对象生命周期还没有结束（没有被删除或被Python的GC回收），否则将会产生未定义行为。 |
