【发布时间】:2013-10-23 11:16:55
【问题描述】:
谁能解释 numpy 的 tile 功能?我无法从http://docs.scipy.org/doc/numpy/reference/generated/numpy.tile.html中给出的示例中弄清楚
【问题讨论】:
标签: python python-3.x numpy
谁能解释 numpy 的 tile 功能?我无法从http://docs.scipy.org/doc/numpy/reference/generated/numpy.tile.html中给出的示例中弄清楚
【问题讨论】:
标签: python python-3.x numpy
它只是重复数组中元素的数量。如果你有一个数组,比如[1,2,3],那么np.tile([1,2,3], 2) 将重复元素两次并创建一个新数组。正如 Thorsten 所解释的,np 总是返回一个数组,即使你给它一个列表。所以用一些例子来解释:
>>> import numpy as np
>>> ar = [1]
>>> np.tile(ar, 2)
array([1, 1])
>>> np.tile(ar, 3)
array([1, 1, 1])
>>> np.tile(ar, 4)
array([1, 1, 1, 1])
>>> new_ar = [1,2,3]
>>> np.tile(new_ar, 2)
array([1, 2, 3, 1, 2, 3])
>>> np.tile(new_ar, 3)
array([1, 2, 3, 1, 2, 3, 1, 2, 3])
# | 1st | 2nd | 3rd | -> Repeats shown.
【讨论】: