99999久久久久久亚洲,欧美人与禽猛交狂配,高清日韩av在线影院,一个人在线高清免费观看,啦啦啦在线视频免费观看www

熱線電話:13121318867

登錄
2022-03-02 閱讀量: 1509
np.tile函數(shù)的用法

In [7]: help(tile)

Help on function tile in module numpy:


tile(A, reps)

Construct an array by repeating A the number of times given by reps.

通過對A按照指定要求重復(fù)若干次來構(gòu)建一個數(shù)組。這個指定要求通過reps參數(shù)來設(shè)定。


If `reps` has length ``d``, the result will have dimension of

``max(d, A.ndim)``.

如果reps參數(shù)的長度為d,則返回的數(shù)組的維數(shù)是max(d,A.ndim)


If ``A.ndim < d``, `A` is promoted to be d-dimensional by prepending new

axes. So a shape (3,) array is promoted to (1, 3) for 2-D replication,

or shape (1, 1, 3) for 3-D replication. If this is not the desired

behavior, promote `A` to d-dimensions manually before calling this

function.

如果A的維數(shù)小于d,則返回的數(shù)組的維數(shù)是d,通過給A追加新的軸來實現(xiàn)。

所以一個shape為(3,)的一維數(shù)組,可以晉級為shape為(1,3)二維數(shù)組,也可以晉級為shape為(1,1,3)的三維數(shù)組。




If ``A.ndim > d``, `reps` is promoted to `A`.ndim by pre-pending 1's to it.

Thus for an `A` of shape (2, 3, 4, 5), a `reps` of (2, 2) is treated as

(1, 1, 2, 2).

如果A的維數(shù)大于d,則reps長度會被晉級為A的維數(shù)。對于reps長度不足的地方會被預(yù)填為1。

所以對于一個shape為(2,3,4,5)的四維數(shù)組A,如果reps參數(shù)被設(shè)定為了(2,2),則reps會被當(dāng)成(1,1,2,2)對待。



Note : Although tile may be used for broadcasting, it is strongly

recommended to use numpy's broadcasting operations and functions.

備注:盡管tile函數(shù)可以被用于廣播,但是我們還是強烈建議您使用numpy的廣播運算和函數(shù)。

Parameters 參數(shù)介紹

----------

A : array_like 一個類數(shù)組

The input array.

reps : array_like 一個類數(shù)組

The number of repetitions of `A` along each axis.指定在某一個軸上重復(fù)的長度。


Returns

-------

c : ndarray

The tiled output array. 返回一個數(shù)組。


See Also 也可以看下repeat和broadcast_to這兩個函數(shù)。

--------

repeat : Repeat elements of an array.

broadcast_to : Broadcast an array to a new shape


Examples

--------

>>> a = np.array([0, 1, 2])

>>> np.tile(a, 2) 在0軸上重復(fù)為原來的二倍

array([0, 1, 2, 0, 1, 2])

>>> np.tile(a, (2, 2)) 在0軸上重復(fù)為原來的二倍,在1軸上重復(fù)為原來的二倍

array([[0, 1, 2, 0, 1, 2],

[0, 1, 2, 0, 1, 2]])

>>> np.tile(a, (2, 1, 2)) 在0軸上重復(fù)為原來的二倍,在1軸上重復(fù)為原來的一倍,在2軸上重復(fù)為原來的二倍

array([[[0, 1, 2, 0, 1, 2]],

[[0, 1, 2, 0, 1, 2]]])


>>> b = np.array([[1, 2], [3, 4]])

>>> np.tile(b, 2) 在0軸上不變,在1軸上重復(fù)為原來的二倍

array([[1, 2, 1, 2],

[3, 4, 3, 4]])

>>> np.tile(b, (2, 1))

array([[1, 2],

[3, 4],

[1, 2],

[3, 4]])


>>> c = np.array([1,2,3,4])

>>> np.tile(c,(4,1))

array([[1, 2, 3, 4],

[1, 2, 3, 4],

[1, 2, 3, 4],

[1, 2, 3, 4]])



下面這個例子可能講的更明白一些

In [8]: tile([1,2],(3,1) )

Out[8]:

array([[1, 2],

[1, 2],

[1, 2]])

從內(nèi)向外不斷擴展,然后原來的A是一維,reps長度為2,那就先需要在原來A的最外面加一層中括號,使其變?yōu)槎S。然后在0軸上的軸長變?yōu)樵瓉淼娜叮?軸上的軸長是原來的一倍。

110.2671
0
關(guān)注作者
收藏
評論(0)

發(fā)表評論

暫無數(shù)據(jù)
推薦帖子