from numpy import *
def swap_columns(my_array, col1, col2):
temp = my_array[:,col1]
my_array[:,col1] = my_array[:,col2]
my_array[:,col2] = temp
Then
swap_columns(data, 0, 1)
Doesn't work. However, calling the code directly
temp = my_array[:,0]
my_array[:,0] = my_array[:,1]
my_array[:,1] = temp
Does. Why is this happening and how can I fix it? The Error says "IndexError: 0-d arrays can only use a single () or a list of newaxes (and a single ...) as an index", which implies the arguments aren't ints? I already tried converting the cols to int but that didn't solve it.