numpy的 - 阵VS asarray [英] Numpy - array vs asarray

查看:163
本文介绍了numpy的 - 阵VS asarray的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

之间有什么numpy的的<一的区别href=\"http://docs.scipy.org/doc/numpy/reference/generated/numpy.array.html#numpy.array\"><$c$c>array()和<一个href=\"http://docs.scipy.org/doc/numpy/reference/generated/numpy.asarray.html#numpy.asarray\"><$c$c>asarray()功能?当你应该使用一个,而不是其他?他们似乎为所有我能想到的输入相同的输出。

What is the difference between Numpy's array() and asarray() functions? When should you use one rather than the other? They seem to generate identical output for all the inputs I can think of.

推荐答案

的<一个href=\"https://github.com/numpy/numpy/blob/bcbed877f42ed6e9b01b2125134db4b6395f1d9d/numpy/core/numeric.py#L413-481\"相对=nofollow>定义 asarray 是:

def asarray(a, dtype=None, order=None):
    return array(a, dtype, copy=False, order=order)

因此​​,它是像阵列,除了它具有较少的选项,复制=假阵列副本= TRUE 默认情况下。

So it is like array, except it has fewer options, and copy = False. array has copy = True by default.

我认为主要的区别是,阵列(默认)可以使对象的副本,而 asarray 不会,除非必要的。

I think the main difference is that array (by default) will make a copy of the object, while asarray will not unless necessary.

这篇关于numpy的 - 阵VS asarray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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