Q:

Write a NumPy program to find the index of the sliced elements as follows from a given 4x4 array

0

Write a NumPy program to find the index of the sliced elements as follows from a given 4x4 array.

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import numpy as np    
x = np.reshape(np.arange(16),(4,4))
print("Original arrays:")
print(x)
print("Sliced elements:")
result = x[[0,1,2],[0,1,3]]
print(result)

Sample Output:

Original arrays:
[[ 0  1  2  3]
 [ 4  5  6  7]
 [ 8  9 10 11]
 [12 13 14 15]]
Sliced elements:
[ 0  5 11]

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now