AttributeError:“module”对象没有属性“flip”,python 2.7

2024-05-02 11:25:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个可能是为Python 3开发的代码,但我的Centos运行的是Python 2.7:

def generateWeights(self, name_list):
    n = len(name_list)
    weights = np.flip(np.arange(1, n), axis=0)
    return weights / np.sum(weights)

我得到了这部分代码:

AttributeError: 'module' object has no attribute 'flip'

有什么我应该安装/更新的,或一个替代代码可以工作吗?在

导入部件:

^{pr2}$

Tags: 代码nameselflenreturndefnplist