Write a NumPy program to calculate cumulative product of the elements along a given axis, sum over rows for each of the 3 columns and product over columns for each of the 2 rows of a given 3x3 array
- برمجة بايثون
- 2021-09-13
- mhanasmh00489829403
الأجوبة
import numpy as np
x = np.array([[1,2,3], [4,5,6]])
print("Original array: ")
print(x)
print("Cumulative product of the elements along a given axis:")
r = np.cumprod(x)
print(r)
print("\nProduct over rows for each of the 3 columns:")
r = np.cumprod(x,axis=0)
print(r)
print("\nProduct over columns for each of the 2 rows:")
r = np.cumprod(x,axis=1)
print(r)
Sample Output:
Original array: [[1 2 3] [4 5 6]] Cumulative product of the elements along a given axis: [ 1 2 6 24 120 720] Product over rows for each of the 3 columns: [[ 1 2 3] [ 4 10 18]] Product over columns for each of the 2 rows: [[ 1 2 6] [ 4 20 120]]
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال