- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试理解 ndarray.data
的含义numpy 中的字段(参见 N 维数组引用页的 memory layout 部分),尤其是对于数组 View 。引用文档:
ndarray.data -- Python buffer object pointing to the start of the array’s data
根据这个描述,我希望这是一个指向 ndarray 实例下的 C 数组的指针。
考虑 x = np.arange(5, dtype=np.float64)
.
表格 y
作为对 x
的看法使用切片:y = x[3:1:-1]
.
我期待 x.data
指向 0.
的位置和 y.data
指向 3.
的位置.我期待 y.data
打印的内存指针因此被 3*x.itemsize
抵消来自 x.data
打印的内存指针的字节,但事实并非如此:
>>> import numpy as np
>>> x = np.arange(5, dtype=np.float64)
>>> y = x[ 3:1:-1]
>>> x.data
<memory at 0x000000F2F5150348>
>>> y.data
<memory at 0x000000F2F5150408>
>>> int('0x000000F2F5150408', 16) - int('0x000000F2F5150348', 16)
192
>>> 3*x.itemsize
24
'data'
输入 __array_interface
与 ndarray 实例关联的字典表现得更像我期望的那样,尽管它本身可能不是指针:
>>> y.__array_interface__['data'][0] - x.__array_interface__['data'][0]
24
So this begs the question, what does the
ndarray.data
give?
提前致谢。
最佳答案
<memory at 0x000000F2F5150348>
是 memoryview
对象位于地址 0x000000F2F5150348
;它提供访问权限的缓冲区位于其他地方。
内存 View 提供了 relevant official documentation 中描述的许多操作,但至少在 Python 端 API 上,它们不提供任何方法来访问它们公开的内存的原始地址。特别是 at whatevernumber
number 不是您要找的。
关于python - numpy 中 View 的 ndarray.data 行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39500356/
在这个例子中,我有一个一维 ndarray 列表,长度为 9,列表有 9 个元素,每个元素有 shape=(2048,) ,所以完全9 * (2048,) , 我得到这些 ndarray来自 mxne
Python/NumPy 中的三种“全部”方法有什么区别?性能差异的原因是什么? ndarray.all() 是否总是三者中最快的? 这是我运行的计时测试: In [59]: a = np.full(
我似乎在 this 中遇到了 XY 问题关于如何判断数组是否共享相同内存的问题。我检查的方式是错误的,我不知道为什么。 举几个例子 test = np.ones((3,3)) test2 = np.a
我在使用 mxnet 进行基本 IO 方面遇到问题。我正在尝试使用 mxnet.io.NDArrayIter 读取内存数据集以在 mxnet 中进行训练。我有下面的代码(为了简洁而精简),它预处理代码
首先,这不是作业问题;而是作业问题。它是与我的工作相关的实际问题的抽象。我真的很感谢所有的意见! 我需要运行类似于下面的计算,按顺序运行数万次,它的计算时间显着影响我的模拟的总持续时间: 在这个抽象中
这个问题在这里已经有了答案: Index multidimensional array with index array (1 个回答) 关闭 2 年前。 我想根据一些坐标从 src ndarray
因此 numpy ndarray 非常方便,因为您只需为任何一维函数 f 和任何 ndarray A 输入 f(A) 即可,它将按元素应用 f。有人告诉我,这也是将函数应用于 ndarray 并避免
我有一个 ndarray 字符串。我想将它转换回 ndarray。我尝试了 newval = np.fromstring(val, dtype=float) 。但它给出了ValueError:字符串大
我正在 python/numpy 中做一些机器学习工作,其中我想用一维 ndarray 索引一个二维 ndarray,这样我就可以得到一个带有索引值的一维数组。 我让它与一些丑陋的代码一起工作,我想知
我想根据某些维度的索引位置数组提取 numpy ndarray 的一部分。让我用一个例子来说明这一点 示例数据 dummy = np.random.rand(5,2,100) X = np.array
这个问题在这里已经有了答案: Find the row indexes of several values in a numpy array (8 个答案) 关闭 2 年前。 我有 a = np.a
我想提取 numpy.ndarray 的第一个轴成为numpy.ndarray的列表. 例如,arr_A包含形状为 (3, 100, 200) 的 numpy ndarray,它将转换为形状为 (10
我一直在尝试用 ndarrays 的 numpy ndarray 转换数组数组。 这是我的数据类型: dt = 'i8,i8,i8,i8,i8,i8,i8,i8,i8,i8,i8,i8,i8,f8,i
我目前正在研究一种可以拆分 numpy.ndarray 的方法进入给定数量的子阵列,只要该数量小于窗口移动的轴。 示例: 给定一个形状为 (15, 40, 3) 的 numpy.ndarray 我想分
我用 arcpy 模块创建了一个 NumPy 结构化数组(称为 arr): arr = arcpy.da.FeatureClassToNumPyArray('MPtest','SHAPE@XYZ',e
是否可以将一个 numpy 数组的特定行的引用存储在另一个 numpy 数组中? 我有一个二维节点数组,例如 nodes = np.array([[1, 2], [2, 3], [3, 4], [4,
我有两个长度相同的 pandas 系列,如下所示: S1 = 0 -0.483415 1 -0.514082 2 -0.515724 3 -0.519375 4
当使用 numpy 时,假设我有一个任意的、以前创建的名为 my_ndarray 的 ndarray。如果可能的话,我希望能够执行以下操作...... my_bytes = my_ndarray.to
我在尝试使用 numpy 打乱多维数组时遇到问题。可以使用以下代码重现该问题: import numpy as np s=(300000, 3000) n=s[0] print ("Allocate"
当您调用 DataFrame.to_numpy() 时,pandas 将找到可以容纳 DataFrame 中所有数据类型的 NumPy 数据类型。但是如何进行反向操作呢? 我有一个“numpy.nda
我是一名优秀的程序员,十分优秀!