0

For example, I have a variable which point to a vector contains many elements in memory, I want to copy element in vector to a numpy array, what should I do except one by one copy? Thx

4

2 回答 2

1

我假设您的向量可以这样表示:-

import array

x = array('l', [1, 3, 10, 5, 6])   # an array using python's built-in array module

然后将其转换为numpy数组将是:-

import numpy as np

y = np.array(x)
于 2012-11-14T16:05:31.927 回答
0

如果数据以原生浮点格式打包在缓冲区中:

a = numpy.fromstring(buf, dtype=float, count=N)
于 2012-11-16T01:03:02.120 回答