0

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?

AndW
  • 726
  • 6
  • 31
  • The `reps` parameter is a bit complicated but fully documented [here](https://numpy.org/doc/stable/reference/generated/numpy.tile.html). So please explain what exactly is unclear after reading the docs. – timgeb Feb 03 '22 at 18:38
  • 1
    @timgeb I don't know so mcuh what it means "promoted to be d-dimensional by prepending new axes" – AndW Feb 03 '22 at 18:40
  • 1
    Yeah that's gibberish if you're not familiar with numpy. It basically says that the function will add new axes as needed. Maybe you should play around with different `reps` and inspect the results. – timgeb Feb 03 '22 at 18:42

1 Answers1

2

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]]
XxJames07-
  • 1,833
  • 1
  • 4
  • 17
  • It starts to get interesting when you pass more than two values. A complete answer should explain that, too. – timgeb Feb 03 '22 at 18:55