如何在a.reshape(3,*(3,4))中理解*(3,4)的用法?

雷切尔·詹妮弗(Rachel Jennifer)
import numpy as np
a = np.arange(36)
print a.shape

(36,)

a = a.reshape(3,*(3,4))
print a.shape

(3,3,4)

首先,我认为*(3,4)可能是一个参数。所以我帮助(np.reshape)

a : array_like
    Array to be reshaped.
newshape : int or tuple of ints
    The new shape should be compatible with the original shape. If
    an integer, then the result will be a 1-D array of that length.
    One shape dimension can be -1. In this case, the value is inferred
    from the length of the array and remaining dimensions.
order : {'C', 'F', 'A'}, optional
    Read the elements of `a` using this index order, and place the elements
    into the reshaped array using this index order.  'C' means to
    read / write the elements using C-like index order, with the last axis
    index changing fastest, back to the first axis index changing slowest.
    'F' means to read / write the elements using Fortran-like index order,
    with the first index changing fastest, and the last index changing
    slowest.
    Note that the 'C' and 'F' options take no account of the memory layout
    of the underlying array, and only refer to the order of indexing.  'A'
    means to read / write the elements in Fortran-like index order if `a`
    is Fortran *contiguous* in memory, C-like order otherwise.

我找不到可以匹配*(3,4)的正确参数,那么如何理解*(3,4)的用法呢?

帕德拉克·坎宁安(Padraic Cunningham)

*(3,4)打开元组的包装,因此它与进行的操作完全相同a.reshape(3,3,4)如果(3,4)是变量,则使用他解包才是真正有意义的,即:

t = (3,4)
a.reshape(3,*t) # same as a.reshape(3, t[0], t[1])

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在jQuery中逐行引用HTML表,col索引-cell(3,4)

如何停止JSONObject以将我的arrayList [3,4]转换为字符串“ [3,4]”

如何从整数中删除尾随零(例如:300 => 3,4 => 4,4,5000 => 5,6060 => 606?

C#控制台应用程序如何检查请求的点是主要的点(-3,4),半径10内

如何转换list1中的list = [1,2,[3,4],[5,6],7,[8,9,10]] = [1,2,3,4,5,6,7,8 ,9,10]在python中?

Python 3,4 getattr无效语法

3,4 轴 pytorch 中的矩阵乘法

为什么在JavaScript中[1,2] + [3,4] =“ 1,23,4”?

如何使用R产生序列(1,2,3 ... n,2,3 ... n,3,4..n ... n-1,n)

如何在Bootstrap 4中获得Bootstrap 3外观?

如何在BeauifulSoup 3中运行BeaufiulSoup4命令?

如何在StructureMap 3中替换ObjectFactory用法

预期input_1具有3个维度,但数组的形状为(3,4)

从文本文件(例如[[1,2],[3,4]])输入到python中的2d列表中

在R中使用自动绘图(ggfortify)绘制主成分3,4

将熊猫数据框从(12,1)重塑为特定形状(3,4)

如何在D3中从V4转换为V3

ValueError:形状为(3,1)的不可广播的输出操作数与广播形状(3,4)不匹配

如何在 Python 3 中使用 OpenCV4 的 FastLineDetector?

使用R中的四对(1,2),(3,4),(5,6),(7,8)中的三对进行6个数字的组合

如何在Swift 3、4和5中编写GCD中的dispatch_after?

如何在Bootstrap 4中从Bootstrap 3中编写可折叠的导航栏?

如何在mp3目录中的每个m4a中“ avconv”?

如何在SAS中比较均值(µ1 + µ2 + µ3)/ 3 =(µ3 + µ4)/ 2:使用'ESTIMATE'或'CONTRAST'?

为什么 stdout_lines [1,2] 和 [3,4] 是字符串而不是数组?

如何在Java中创建简单的4x3二维数组?

如何在d3v4中的两个点之间绘制箭头?

如何在Bootstrap 4中使.py-md-6覆盖.p-3?

如何在angular4单元测试中忽略第3方组件的html标签?