Articles → NUMPY → Broadcast capability of an array in NumPy

Broadcast capability of an array in NumPy






Example




import numpy as np

arr = np.arange(0,10)

# print array
print("Before change", arr)

#Broadcast
arr[0:2] = 200

# print array
print("After change", arr)




Picture showing the output of broadcast capability of an array in NumPy

Click to Enlarge




Changing the value of all the elements in one go




import numpy as np


arr = np.arange(0,10)

arr[:] = 100

# print array
print(arr)




Picture showing the output of updating all values in array in one go

Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Thursday, March 28, 2019

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250