Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

numpy
python
communitycreator

What is the numpy.tile() function in Python?

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code

Overview

In Python, the tile() function is used to construct an array by repeating the input array the number of times as specified by the reps.

Syntax

numpy.tile(A, reps)
Syntax for the tile() function in Python

Parameter value

This function takes the following parameter values:

  • A: The is the input array.
  • reps: This is the number of repetitions for the input array.

Return value

This function returns aa tiled output array.

Example

import numpy as np
# creating an input array
a = np.array([1,2,3,4,5])
# calling the tile() function
my_array = np.tile(a, 2)
# printing the tiled array
print(my_array)

Explanation

  • Line 1: We import the numpy module.
  • Line 3: We create an input array, a, using the array() function.
  • Line 6: We call the tile() function and pass a and 2 as arguments, meaning we are creating a tiled array having two repetitions of the array, a. The result is assigned to a variable, my_array.
  • Line 9: We print the new array, my_array.

RELATED TAGS

numpy
python
communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code
Keep Exploring