gorgonia / tensor

package tensor provides efficient and generic n-dimensional arrays in Go that are useful for machine learning and deep learning purposes
Apache License 2.0
359 stars 49 forks source link

SortIndex() functions differently from numpy's argsort(). #140

Closed ksw2000 closed 5 months ago

ksw2000 commented 5 months ago
import numpy as np
a = np.array([9, 8, 7, 6, 5, 4])
b = np.argsort(a)
print(a) # [9 8 7 6 5 4]
print(b) # [5 4 3 2 1 0]

We can see that the original numpy array is not changed after calling argsort.

But in golang tensor package, the input array is changed.

func TestSortIndex(t *testing.T) {
    in := []int{9, 8, 7, 6, 5, 4}
    out := SortIndex(in)
    fmt.Println(in) // [4 5 6 7 8 9]
    fmt.Println(out) // [5 4 3 2 1 0]
}