---
title: 函数：numpy_contiguous_to_ptr
description: "该接口即将废弃，建议使用acl.util.bytes_to_ptr接口。"
url: https://www.hiascend.com/document/detail/zh/Atlas200IDKA2DeveloperKit/latest/Application%20Development%20Guide/aadgp/aclpythondevg_01_0051.html
sourcePath: /source/zh/Atlas200IDKA2DeveloperKit/23.0.RC2/Application Development Guide/aadgp/aclpythondevg_01_0051.html
indexId: c587612bacc0b2de5ed77058d0af954113c65795c5290ad18a945be36c66ec3d108
---
# 函数：numpy_contiguous_to_ptr

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


| C函数原型 | 无 |
| --- | --- |
| Python函数 | ptr, data\_out = acl.util.numpy\_contiguous\_to\_ptr(data\_in) |
| 函数功能 | 获取numpy.ndarry数组的内存数据指针地址。 若传入的numpy.ndarry数组在内存上是非行连续的，则先将其内存转行连续，然后再获取转换后的numpy.ndarry数组转换成为内存数据指针地址。 |
| 输入说明 | 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.ndarry对象生命周期还没有结束（没有被删除或被Python的GC回收），否则将会产生未定行为。 |
