When you index an axis with a number, the result removes that axis, so you went from a 3x2 matrix to a 2-length vector. Broadcasting lines up to the leftmost axis not the rightmost, so 15x2 is incompatible with 2. Besides using a transpose to get a 1x2 matrix, you can actually keep the axis in the first place, you just have to index with a 1-length range instead of a number centroids[1:1, :].
It’s a bit confusing going between, it’s rooted in how C is row-major and Julia is column-major but they both try to adhere to conventional matrix notation. If it helps, here’s some pointers:
A single dimension vector is more like a column vector with #rows in Julia, but a row vector with #columns in Numpy.
A matrix is conventionally #rows x #columns, both Numpy and Julia adhere to this.
When you stack matrices to go 3D, Julia continues to add axes to the right #rows x #columns x #pages. For example, a 3x2x4 array stacks 3x2 matrices. Numpy continues to add axes to the left #pages x #rows x #columns. For example, a 4x3x2 array stacks 3x2 matrices.