InterviewSolution
Saved Bookmarks
| 1. |
You are given a numpy array and a new column as inputs. How will you delete the second column and replace the column with a new column value? |
|
Answer» [[35 53 63][72 12 22][43 84 56]] New Column values: [ 20 30 40]Solution: IMPORT numpy as np#inputsinputArray = np.array([[35,53,63],[72,12,22],[43,84,56]])new_col = np.array([[20,30,40]])# DELETE 2nd columnarr = np.delete(inputArray , 1, axis = 1)#insert new_col to arrayarr = np.insert(arr , 1, new_col, axis = 1)print (arr) |
|