| 1. |
Write a program for interchanging two axes of the NumPy array. |
|
Answer» This can be achieved by using the swapaxes method of NumPy. The below image illustrates the meaning of swapping axes. import numpy as nparr = np.array([[1,2,3]]) print("Original array: ") print(arr) #Swap axes axis_swapped_arr = np.swapaxes(arr,0,1) print("Transformed array: ") print(axis_swapped_arr) Output: Original array:[[1 2 3]] Transformed array: [[1] [2] [3]] Conclusion The popularity of the NumPy package has grown immensely among the data science and python developers community ever since it was first introduced in 2005 due to the wide range of high-performing functionalities it offers. This is why it becomes essential to learn and be prepared for the interview questions about this package. In this article, we have seen the most commonly asked NumPy interview questions for freshers and experienced people, along with some questions on writing python programs which make use of NumPy functions. References Interview Guides
|
|