Rok_Petka
(Rok Petka)
November 15, 2021, 4:01pm
1
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!
skillian
(Sean Killian)
November 15, 2021, 5:09pm
2
I think you’re probably off to the right start with append
. Can you share what you tried with append
?
Rok_Petka
(Rok Petka)
November 15, 2021, 6:02pm
3
Thanks for the reply. I think the append version is way off:
https://play.golang.org/p/bj1cClEJGDf
skillian
(Sean Killian)
November 15, 2021, 6:07pm
4
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
Rok_Petka
(Rok Petka)
November 15, 2021, 6:10pm
5
Thank you, ohhh secrets are in details
system
(system)
Closed
February 13, 2022, 6:10pm
6
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.