Mean Squared Error in Numpy?

前端 未结 6 1482
忘掉有多难
忘掉有多难 2020-12-13 12:01

Is there a method in numpy for calculating the Mean Squared Error between two matrices?

I\'ve tried searching but found none. Is it under a different name?

I

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-13 12:15

    You can use:

    mse = ((A - B)**2).mean(axis=ax)
    

    Or

    mse = (np.square(A - B)).mean(axis=ax)
    
    • with ax=0 the average is performed along the row, for each column, returning an array
    • with ax=1 the average is performed along the column, for each row, returning an array
    • with ax=None the average is performed element-wise along the array, returning a scalar value

提交回复
热议问题