1. Write a Python Numpy program to obtain the square and cubic of initial array.
The output is:
Initial array [0, 1, 2, 3, 4, 5]
Expected Answer:
Square of array: [ 0 1 4 9 16 25]
Cubic of array: [ 0 1 8 27 64 125]
Sample Answer:
import numpy as np a = np.arange(6) print("Initial array", a) b_square = np.power(a, 2) c_cubic = np.power(a, 3) print("\nSquare of array:", b_square) print("Cubic of array:", c_cubic)
More Exercises:
Python String ExercisesMore Numpy Exercises:
Numpy String ExercisesMore Pandas Exercises:
Pandas Series ExercisesMore Tutorials:
Python Installation - Linux (Ubuntu)