I'm quite new to python and I'm working on some data manipulation. I thought the indexing in numpy would be [row][column], but it's not what I see when I execute in python. Below is a simple example of how python is behaving. I don't understand why I get the same results for the last two commands:
import numpy as num
test_arr = num.array([[1, 2, 3],[4, 5, 6], [7, 8, 9]],dtype=num.float32)
test_arr[0][:]
array([1., 2., 3.], dtype=float32)
test_arr[:][0]
array([1., 2., 3.], dtype=float32)
I would expect
test_arr[0][:]
array([1., 2., 3.], dtype=float32)
test_arr[:][0]
array([1., 4., 7.], dtype=float32)
Can someone explain why python behaves as it does and how to get the 0th index of all rows?
[:]only creates a copy; with arrays it's a view. So it's doing nothing in your examples. Each[]is a separate indexing step. Take time to read numpy basics, such as this indexing page: docs.scipy.org/doc/numpy/reference/arrays.indexing.html