我知道我可以使用我的define函数对数组进行排序,就像这样:
bool cmp(int a, int b){
return a > b;
}
class SortTest{
public :
void testSort(){
int a[] = { 1, 3, 4, 7, 0 };
int n = 5;
sort(a, a + n, cmp); //work
for (int i = 0; i < n; i++){
cout << a[i] << " ";
}
}
};
Run Code Online (Sandbox Code Playgroud)
但是如果我在SortTest类中使用函数cmp,它就不起作用了.
class SortTest{
public :
bool cmp(int a, int b){
return a > b;
}
void testSort(){
int a[] = { 1, 3, 4, 7, …Run Code Online (Sandbox Code Playgroud) 我使用numpy来计算矩阵乘法.如果我使用t = t*x,它可以正常工作,但如果我使用t*= x,它就不会.我需要使用t = t*x吗?
import numpy as np
if __name__ == '__main__':
x = [
[0.9, 0.075, 0.025],
[0.15, 0.8, 0.05],
[0.25, 0.25, 0.5]
]
t = [1, 0, 0]
x = np.matrix(x)
t = np.matrix(t)
t = t * x # work , [[ 0.9 0.075 0.025]]
# t *= x # not work? always [[0 0 0]]
print t
Run Code Online (Sandbox Code Playgroud)