What is the difference between np.tile and np.repeat?

Quick Overview

Asks how NumPy's tile and repeat functions differ when replicating array data. Tests whether you know which one copies the whole array and which copies each element, how both behave on 2D arrays with and without an axis, and when broadcasting is the better choice.

What is the difference between np.tile and np.repeat?

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

What is the difference between `np.tile` and `np.repeat`? ```hint Compare the order Run both on `[1, 2, 3]` with a count of 2 and compare the order of the output, then try a 2D array with and without an axis. ``` ### What a Strong Answer Covers - What each function copies: the whole array or each element - How each behaves on a 2D array, including what happens when no axis is given - The options each accepts, such as a tuple of repetitions, per-element counts and an axis - When you would reach for one or the other ### Follow-up Questions - What does `np.repeat` return for a 2D array when you don't pass `axis`? - How would you build every pair of values from two 1D arrays using these two functions? - When would `np.broadcast_to` be a better choice than either?

Overview: Asks how NumPy's tile and repeat functions differ when replicating array data. Tests whether you know which one copies the whole array and which copies each element, how both behave on 2D arrays with and without an axis, and when broadcasting is the better choice.

General logo
General
Nov 25, 2026
easyData ScientistOtherData Manipulation (SQL/Python)
0
0

What is the difference between np.tile and np.repeat?

What a Strong Answer Covers Guidance

  • What each function copies: the whole array or each element
  • How each behaves on a 2D array, including what happens when no axis is given
  • The options each accepts, such as a tuple of repetitions, per-element counts and an axis
  • When you would reach for one or the other

Follow-up Questions Guidance

  • What does np.repeat return for a 2D array when you don't pass axis ?
  • How would you build every pair of values from two 1D arrays using these two functions?
  • When would np.broadcast_to be a better choice than either?