Q:

Write a NumPy program to access an array by column

0

Write a NumPy program to access an array by column.

All Answers

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

import numpy as np
x= np.arange(9).reshape(3,3)
print("Original array elements:")
print(x)
print("Access an array by column:")
print("First column:")
print(x[:,0])
print("Second column:")
print(x[:,1])
print("Third column:")
print(x[:,2])

Sample Output:

Original array elements:
[[0 1 2]
 [3 4 5]
 [6 7 8]]
Access an array by column:
First column:
[0 3 6]
Second column:
[1 4 7]
Third column:
[2 5 8]

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