AILearn
Problems

1. Sum of Array Elements

Easy

Write a function array_sum(arr) that returns the sum of all elements in a numpy array without using np.sum().

Example:

Input: arr = [1, 2, 3, 4, 5]

Output: 15

Constraints:

  • Array length: 1 <= len(arr) <= 1000
  • Array values: -1000 <= arr[i] <= 1000
  • Test Cases

    Test Case 1
    Input: [1, 2, 3, 4, 5]
    Expected: 15
    Test Case 2
    Input: [10, 20, 30]
    Expected: 60
    Test Case 3
    Input: [-1, 0, 1]
    Expected: 0
    + 2 hidden test cases
    Python 3
    Loading editor...
    Console Output
    Click "Run" to test your code or "Submit" to submit your solution.