Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Numpy exercise
  • pandas
  • Matplotlib
  • Data visulisation
  • EDA
  • Machin Learning
  • Deep Learning
  • NLP
  • Data science
  • ML Tutorial
  • Computer Vision
  • ML project
Open In App
Next Article:
numpy.tile() in Python
Next article icon

numpy.tile() in Python

Last Updated : 28 Mar, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

The numpy.tile() function constructs a new array by repeating array - 'arr', the number of times we want to repeat as per repetitions. The resulted array will have dimensions max(arr.ndim, repetitions) where, repetitions is the length of repetitions. If arr.ndim > repetitions, reps is promoted to arr.ndim by pre-pending 1’s to it. If arr.ndim < repetitions, reps is promoted to arr.ndim by pre-pending new axis. Syntax : 

numpy.tile(arr, repetitions)

Parameters : 

array       : [array_like]Input array.  repetitions : No. of repetitions of arr along each axis. 

Return : 

An array with repetitions of array - arr as per d, number of times we want to repeat arr  

Code 1 : 

Python
# Python Program illustrating # numpy.tile()  import numpy as geek  #Working on 1D arr = geek.arange(5) print("arr : \n", arr)  repetitions = 2 print("Repeating arr 2 times : \n", geek.tile(arr, repetitions))  repetitions = 3 print("\nRepeating arr 3 times : \n", geek.tile(arr, repetitions)) # [0 1 2 ..., 2 3 4] means [0 1 2 3 4 0 1 2 3 4 0 1 2 3 4] # since it was long output, so it uses [ ... ] 

Output : 

arr :   [0 1 2 3 4] Repeating arr 2 times :   [0 1 2 3 4 0 1 2 3 4]  Repeating arr 3 times :   [0 1 2 ..., 2 3 4]

Code 2 : 

Python
# Python Program illustrating # numpy.tile()  import numpy as geek  arr = geek.arange(3) print("arr : \n", arr)  a = 2   b = 2   repetitions = (a, b) print("\nRepeating arr : \n", geek.tile(arr, repetitions)) print("arr Shape : \n", geek.tile(arr, repetitions).shape)  a = 3   b = 2    repetitions = (a, b) print("\nRepeating arr : \n", geek.tile(arr, repetitions)) print("arr Shape : \n", geek.tile(arr, repetitions).shape)  a = 2 b = 3   repetitions = (a, b) print("\nRepeating arr : \n", geek.tile(arr, repetitions)) print("arr Shape : \n", geek.tile(arr, repetitions).shape) 

Output : 

arr :   [0 1 2]  Repeating arr :   [[0 1 2 0 1 2]  [0 1 2 0 1 2]] arr Shape :   (2, 6)  Repeating arr :   [[0 1 2 0 1 2]  [0 1 2 0 1 2]  [0 1 2 0 1 2]] arr Shape :   (3, 6)  Repeating arr :   [[0 1 2 ..., 0 1 2]  [0 1 2 ..., 0 1 2]] arr Shape :   (2, 9)

Code 3 : (repetitions == arr.ndim) == 0 

Python
# Python Program illustrating # numpy.tile()  import numpy as geek  arr = geek.arange(4).reshape(2, 2) print("arr : \n", arr)  a = 2   b = 1   repetitions = (a, b) print("\nRepeating arr : \n", geek.tile(arr, repetitions)) print("arr Shape : \n", geek.tile(arr, repetitions).shape)  a = 3   b = 2    repetitions = (a, b) print("\nRepeating arr : \n", geek.tile(arr, repetitions)) print("arr Shape : \n", geek.tile(arr, repetitions).shape)  a = 2 b = 3   repetitions = (a, b) print("\nRepeating arr : \n", geek.tile(arr, repetitions)) print("arr Shape : \n", geek.tile(arr, repetitions).shape) 

Output : 

arr :   [[0 1]  [2 3]]  Repeating arr :   [[0 1]  [2 3]  [0 1]  [2 3]] arr Shape :   (4, 2)  Repeating arr :   [[0 1 0 1]  [2 3 2 3]  [0 1 0 1]  [2 3 2 3]  [0 1 0 1]  [2 3 2 3]] arr Shape :   (6, 4)  Repeating arr :   [[0 1 0 1 0 1]  [2 3 2 3 2 3]  [0 1 0 1 0 1]  [2 3 2 3 2 3]] arr Shape :   (4, 6)

References : https://docs.scipy.org/doc/numpy/reference/generated/numpy.tile.html Note : These codes won’t run on online IDE's. Please run them on your systems to explore the working .


Next Article
numpy.tile() in Python

M

Mohit Gupta
Improve
Article Tags :
  • Misc
  • Python
  • Python-numpy
  • Python numpy-arrayManipulation
Practice Tags :
  • Misc
  • python

Similar Reads

    numpy.take() in Python
    The numpy.take() function returns elements from array along the mentioned axis and indices. Syntax: numpy.take(array, indices, axis = None, out = None, mode ='raise') Parameters : array : array_like, input array indices : index of the values to be fetched axis : [int, optional] axis over which we ne
    2 min read
    numpy.roll() in Python
    The numpy.roll() function rolls array elements along the specified axis. Basically what happens is that elements of the input array are being shifted. If an element is being rolled first to the last position, it is rolled back to the first position. Syntax : numpy.roll(array, shift, axis = None) Par
    2 min read
    numpy.zeros() in Python
    numpy.zeros() function creates a new array of specified shapes and types, filled with zeros. It is beneficial when you need a placeholder array to initialize variables or store intermediate results. We can create 1D array using numpy.zeros().Let's understand with the help of an example:Pythonimport
    2 min read
    numpy.repeat() in Python
    The numpy.repeat() function repeats elements of the array - arr. Syntax :  numpy.repeat(arr, repetitions, axis = None) Parameters :  array : [array_like]Input array. repetitions : No. of repetitions of each array elements along the given axis. axis : Axis along which we want to repeat values. By def
    2 min read
    Numpy size() function | Python
    numpy.size() function in Python is used to count the number of elements in a NumPy array. You can use it to get the total count of all elements, or to count elements along a specific axis, such as rows or columns in a multidimensional array. This makes it useful when quickly trying to understand the
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences