解决ret = umr_sum(arr, axis, dtype, out, keepdims)RuntimeError: The size of tensor a (400) must match

Posted 沉迷单车的追风少年

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了解决ret = umr_sum(arr, axis, dtype, out, keepdims)RuntimeError: The size of tensor a (400) must match相关的知识,希望对你有一定的参考价值。

项目场景:

numpy np.mean()计算平均值


问题描述:

完整报错如下:

Traceback (most recent call last):
  File "test_wq.py", line 88, in <module>
    valid_cls(model, im_test_data, sk_test_data)
  File "test_wq.py", line 54, in valid_cls
    avg = np.mean(presicion_array)
  File "<__array_function__ internals>", line 6, in mean
  File "/root/anaconda3/envs/dpm-pc-gen/lib/python3.7/site-packages/numpy/core/fromnumeric.py", line 3373, in mean
    out=out, **kwargs)
  File "/root/anaconda3/envs/dpm-pc-gen/lib/python3.7/site-packages/numpy/core/_methods.py", line 160, in _mean
    ret = umr_sum(arr, axis, dtype, out, keepdims)
RuntimeError: The size of tensor a (400) must match the size of tensor b (20) at non-singleton dimension 0

原因分析

以上是关于解决ret = umr_sum(arr, axis, dtype, out, keepdims)RuntimeError: The size of tensor a (400) must match的主要内容,如果未能解决你的问题,请参考以下文章

numpy和pandas axis的差异

numpy.array()是否等于numpy.stack(...,axis = 0)?

数据分析&数据挖掘数组的排序

Python中numpy.apply_along_axis()函数的用法

np.append()

js常用方法-----数组