如何将数据从numpy数组复制到另一个数组 [英] How to copy data from a numpy array to another

查看:114
本文介绍了如何将数据从numpy数组复制到另一个数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在不修改数组a地址的情况下,将数据从数组b复制到数组a的最快方法是什么.我需要这样做是因为外部库(PyFFTW)使用了指向无法更改的数组的指针.

What is the fastest way to copy data from array b to array a, without modifying the address of array a. I need this because an external library (PyFFTW) uses a pointer to my array that cannot change.

例如:

a = numpy.empty(n, dtype=complex)
for i in xrange(a.size):
  a[i] = b[i]

有没有可能做到这一点?

It is possible to do it without a loop?

推荐答案

我相信

a = numpy.empty_like (b)
a[:] = b

将快速制作一个深层副本.正如Funsi所提到的,最新版本的numpy还具有copyto函数.

will make a deep copy quickly. As Funsi mentions, recent versions of numpy also have the copyto function.

这篇关于如何将数据从numpy数组复制到另一个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆