首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >“numpy.reshape”和“ndarray.reshape”是如何等同的?

“numpy.reshape”和“ndarray.reshape”是如何等同的?
EN

Stack Overflow用户
提问于 2020-01-15 15:21:57
回答 1查看 297关注 0票数 2

我有一个关于ndarray.reshape的结构的问题。我已经读过,numpy.reshape()ndarray.reshape是python中用来重塑数组的等效命令。

据我所知,numpy是一个定义reshape方法的对象。所以在numpy.reshape()中使用点运算符对我来说是可以理解的。但是说到ndarray.reshape,我不明白点运算符是如何工作的。ndarray.reshape中没有对numpy对象的引用;它如何知道reshape与numpy对象相关?

EN

回答 1

Stack Overflow用户

发布于 2020-01-15 16:08:49

我可能理解了一些错误,但通常numpy引用实际的Numpy模块,通过调用numpy.reshape调用静态函数,还需要将数组作为第一个参数传递给它,而ndarray位则服从于实际的numpy数组。示例:

代码语言:javascript
复制
# import the module here
import numpy

# create an vector of 9 elements
arr = numpy.random.rand(1,9)

# and now I call the 'static' version of the reshape method:
arr2 = numpy.reshape(arr, (3,3))

# and here I just call the reshape method of the existing array
arr3 = arr.reshape((3,3))

本质上,这两行代码是等价的,因此arr2arr3包含相同的3x3数组。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59754486

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档