Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Python NumPy repeat Function Syntax

numpy.repeat(arr, repetitions, axis = None)
Comment

Python NumPy repeat Function Example

# welcome to softhunt.net
# Python Program illustrating
# numpy.repeat()

import numpy as np

arr = np.arange(6).reshape(2, 3)
print("arr : 
", arr)

repetitions = 2
print("
Repeating arr : 
", np.repeat(arr, repetitions, 1))
print("arr Shape : 
", np.repeat(arr, repetitions).shape)


repetitions = 2
print("
Repeating arr : 
", np.repeat(arr, repetitions, 0))
print("arr Shape : 
", np.repeat(arr, repetitions).shape)
	
repetitions = 3
print("
Repeating arr : 
", np.repeat(arr, repetitions, 1))
print("arr Shape : 
", np.repeat(arr, repetitions).shape)
Comment

repeat a numpy array

a = np.array([0, 1, 2])
>>> np.tile(a, 2)
array([0, 1, 2, 0, 1, 2])
>>> np.tile(a, (2, 2))
array([[0, 1, 2, 0, 1, 2],
       [0, 1, 2, 0, 1, 2]])
>>> np.tile(a, (2, 1, 2))
array([[[0, 1, 2, 0, 1, 2]],
       [[0, 1, 2, 0, 1, 2]]])
Comment

Python NumPy repeat Function Example Working with 1D array

# welcome to softhunt.net
# Python Program illustrating
# numpy.repeat()

import numpy as np

#Working on 1D
arr = np.arange(5)
print("arr : 
", arr)

repetitions = 2
a = np.repeat(arr, repetitions)
print("
Repeating arr 2 times : 
", a)
print("Shape : ", a.shape)

repetitions = 3
a = np.repeat(arr, repetitions)
print("
Repeating arr 3 times : 
", a)
# [0 0 0 ..., 4 4 4] means [0 0 0 1 1 1 2 2 2 3 3 3 4 4 4]
# since it was long output, so it uses [ ... ]
print("Shape : ", a.shape)
Comment

PREVIOUS NEXT
Code Example
Python :: How can Clone or Duplicate a Row Using np.tile 
Python :: Python NumPy hsplit Function 
Python :: python os.listdir attributes 
Python :: assignment 8.4 python data structures 
Python :: pytorch Jaccard Index 
Python :: pass dictionary to random forest regressor 
Python :: __ge__ 
Python :: how to fetch limited rows in pandas dataframe using sqlalchemy 
Python :: Program to get number of consecutive repeated substring 
Python :: 16. count total numbers of uppercase and lowercase characters in input string python 
Python :: Create a list of multiples of 3 from 0 to 20. 
Python :: Convertion of number into binary using NumPy binary_repr 
Python :: should either include a `queryset` attribute, 
Python :: # find all text files in directory or any type of files in directory 
Python :: how to calculate iqr in pandas 
Python :: Remove Brackets from List Using for loop 
Python :: run server localhost for shar file 
Python :: Python script to download all images from a website to a specified folder with BeautifulSoup 
Python :: list average python recursion 
Python :: python readlines  
Python :: how do i access individual elements of matrix in python? 
Python :: sklearn encoding pipelin 
Python :: Filling a missing value in a pandas data frame with an if statement based on a condition 
Python :: ax pie rounding 
Python :: ring Creating a Multi-Dimensional Array using List 
Python :: nnumpy matrix count non negative values 
Python :: equivalent of geom smooth function in python using plotline lib 
Python :: Use of OfficeApi 
Python :: Print the numbers assigned to the list values in python 
Python :: get picamera feed 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =