首页 > 解决方案 > 在 Python 中使用列表更改二维数组中的值范围

问题描述

在 python 中,我有一个大小为 13 的二维数组,每个元素都是大小为 16 的列表。我想使用以下方法将此数组中的所有值转换为不同的范围。

((old value - old min)/(old max - old min)) * (new max - new min) + new min

我正在使用类似的东西 -

a_list = [1, 2, 3]

multiplied_list = [element * 2 for element in a_list]

print(multiplied_list)

我收到以下错误

"unsupported operand type(s) for -: 'list' and 'int' "

谢谢你的帮助!

标签: pythonarrayslistrange

解决方案


我想通了,我必须使用 numpy.array() 将二维数组从列表转换为浮点数组


推荐阅读