Q:

Write a NumPy program to broadcast on different shapes of arrays where a(,3) + b(3)

0

Write a NumPy program to broadcast on different shapes of arrays where a(,3) + b(3).

The a variable has a shape of (, 3), while b only has a shape of 3.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import numpy as np    
p = np.array([[0], [10], [20]]) 
q= np.array([10, 11, 12]) 
print("Original arrays:")
print("Array-1")
print(p)
print("Array-2")
print(q)
print("\nNew Array:")
new_array1 = p + q 
print(new_array1)

Sample Output:

Original arrays:
Array-1
[[ 0]
 [10]
 [20]]
Array-2
[10 11 12]

New Array:
[[10 11 12]
 [20 21 22]
 [30 31 32]]

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now