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 :: install play sound python terminal 
Python :: python if any element in string 
Python :: python path to python executable 
Python :: get column pandas 
Python :: python spammer 
Python :: python replace nth occurrence in string 
Python :: tab of nbextensions not showing in jupyter notebook 
Python :: decode multipart/form-data python 
Python :: python for loop get iteration number 
Python :: __new__ python 
Python :: python list fill nan 
Python :: how to use cos in python 
Python :: how to find in which directory my python code is running 
Python :: python virtualenv 
Python :: notion python api 
Python :: herencia python 
Python :: how to remove quasi constant column in pandas dataframe 
Python :: breadth first search python 
Python :: userregisterform 
Python :: exclude last value of an array python 
Python :: python print green 
Python :: how to sum all the numbers in a list in python 
Python :: calculate mean median mode in python 
Python :: python 3d array 
Python :: _ variable in python 
Python :: create pandas dataframe from dictionary 
Python :: python sort the values in a dictionary 
Python :: if statement in one-line for loop python 
Python :: Python program to draw hexagon 
Python :: subtract number from each element in list python 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =