How to concatenate two matrices horizontally

Hey there! New to golang here. I’m struggling with concatenating two matrices, e.g.:
mat1:

[[1,2,3],
[4,5,6]]

mat2:

[[7,8,9],
[10,11,12]]

into:
mat3:

[[1,2,3,7,8,9],
[4,5,6,10,11,12]]

Google has practically no solution. I came so far (also tried with append but the problem is [][]float64):
https://play.golang.org/p/8At0utgLgl3

Any help appreciated, thank you!

I think you’re probably off to the right start with append. Can you share what you tried with append?

Thanks for the reply. I think the append version is way off:
https://play.golang.org/p/bj1cClEJGDf

They’re both really close; the only thing you have to change in the one with append is to set mat4 to a [][]float64, not a []float64, and then add the index, i, to your mat4 slice of slices when you loop through mat1: The Go Playground

1 Like

:slight_smile: Thank you, ohhh secrets are in details :+1: