Numpy tile allows you to repeat the whole NumPy array in one dimension or two dimensions. There is also another function that allows you to repeat elements of the array. It is numpy.repeat(). But in case you want to repeat the whole array then the NumPy tile() method is used. In this entire tutorial, you will know how to implement numpy tile() method with examples.
Steps to implement NumPy tile function
Step 1: Import all the required libraries
Here in our example, we are using only the NumPy array so let’s import them using the import statement.
import numpy as np
Step 2: Create a dummy array
The second step is to create a sample array where you will implement the various examples. You can create a NumPy array using the numpy.array() method . I will use the tile() method both on the 1D array and 2D array. So let’s create them.
1D Numpy array
array_1d = np.array([10,20,30])
2D Numpy array
Step 3: Apply the numpy tile method
After the creation of the NumPy array let’s apply the tile method. There are many ways to apply it. Let’s explore all the examples.
Example 1: Repeating over columns
To repeat the array over the columns then you have to pass the value as the second argument inside the tile() method. Execute the below lines of code.
2 D array
Example 2: Repeating array over Rows
To repeat the array over rows then you have to pass the tuple (no_of_rows, no_of_columns) as an argument to the tile() method. For example, I want to repeat the array for 2 rows then I will execute the following code.
1 D array
Example 2: Repeating array over Rows and columns
In the above two examples, you have repeated arrays over columns or rows. Now let’s repeat the array in both rows and columns. To do so you have to pass both the columns and rows as an argument of the tile() method.
These are the examples on the NumPy tile that I have aggregated for you. Numpy tile() allows you to easily repeat your NumPy arrays along with columns or rows. I hope this tutorial has cleared your all queries on tile() method. Even if you have doubt then you can contact us for more help.
Join our list
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.