You can replace the first column as follows:
>>> a = np.zeros((2,2), dtype=np.int) >>> a[:, 0] = 1 >>> a array([[1, 0], [1, 0]])
Here a[:, 0] means "select all rows from column 0". The value 1 is passed along this selected column, creating the desired array (there is no need to use the list [1, 1] , although you can).
Your syntax a[:][0] means "select all rows from array a , and then select the first row." Similarly, a[0][:] means "select the first line of a , and then select the entire line again." That's why you can successfully replace rows, but not columns - you need to make a choice for axis 1, and not just for axis 0.
source share