简体   繁体   English

python numpy reshape(v.shape)和reshape(* v.shape)之间的区别

[英]Python numpy difference between reshape(v.shape) & reshape(*v.shape)

I found myself struggled in the following two region of codes(which exactly did the same job),can anyone tell me what the difference? 我发现自己在下面的两个代码区域(确实完成了相同的工作)中挣扎,有人能告诉我有什么区别吗?

Code1: 代码1:

v = np.zeros((2,5))
value_one = np.linspace(-1.4, 1.3, num=v.size).reshape(*v.shape)

Code2: 代码2:

v = np.zeros((2,5))
value_two = np.linspace(-1.4, 1.3, num=v.size).reshape(v.shape)

Since reshape can accept either ints or tuple of ints both version are ok. 由于reshape可以接受整数或整数元组,所以两个版本都可以。 You can verify by 您可以通过以下方式验证

value_one = np.linspace(-1.4, 1.3, num=10).reshape(2,5)

value_one = np.linspace(-1.4, 1.3, num=10).reshape((2,5))

The stared version *v.shape will strip the tuple to its elements. *v.shape版本*v.shape将把元组剥离到其元素上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM