2. Write a Python Numpy program to generate a new array after divided by two from initial array.
The output is:
Initial array = [1, 2, 3, 4, 5]
Expected Answer:
Initial array: [1 2 3 4 5]
New array: [0.5 1. 1.5 2. 2.5]
Sample Answer:
import numpy as np a = np.arange(1, 6) print("Initial array:", a) Divisive_2 = np.true_divide(a, 2) print("\nNew array:", Divisive_2)
More Exercises:
Python String ExercisesMore Numpy Exercises:
Numpy String ExercisesMore Pandas Exercises:
Pandas Series ExercisesMore Tutorials:
Python Installation - Linux (Ubuntu)