NumPy: Sum and compute the product of a NumPy array elements
NumPy: Array Object Exercise-99 with Solution
Write a NumPy program to sum and compute the product of a NumPy array elements.
import numpy as np x = np.array([10, 20, 30], float) print("Original array:") print(x) print("Sum of the array elements:") print(x.sum()) print("Product of the array elements:") print(x.prod())
Original array: [ 10. 20. 30.] Sum of the array elements: 60.0 Product of the array elements: 6000.0
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a NumPy program to convert the raw data in an array to a binary string and then create an array.
Next: Write a NumPy program to take values from a source array and put them at specified indices of another array.
What is the difficulty level of this exercise?
Test your Python skills with w3resource's quiz
Python: Tips of the Day
>>> m = [x ** 2 for x in range(5)] >>> m [0, 1, 4, 9, 16]
- New Content published on w3resource:
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework