简体   繁体   中英

Cloning row in numpy.tile

This answer https://stackoverflow.com/a/1582742/13326667 has details on cloning row using numpy.tile.

>>> tile(array([1,2,3]), (3, 1))
array([[1, 2, 3],
       [1, 2, 3],
       [1, 2, 3]])

What is the purpose of (3,1) here? Can someone explain what the 3 means and the 1 means?

3 is the number of times he have to clone it horizontally

and 1 is the number of times he have to clone it vertically:

for example if you have:

import numpy as np

tile = np.tile(
np.array([
    [1,2,3], #<- row 1 here
    [1,2,3]  #<- row 2 here
]),(2,2)
)
print(tile)

you would get the array, cloned 2 times vertically and 2 times horizontally:

[[1 2 3 1 2 3]
 [1 2 3 1 2 3]
 [1 2 3 1 2 3]
 [1 2 3 1 2 3]]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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