【发布时间】:2017-11-13 15:28:11
【问题描述】:
我有以下转换数字列表的函数:
import numpy as np
from math import *
def walsh_transform(x):
if len(x) > 3:
n = len(x)
m = trunc(log(n, 2))
x = x[0:2 ** m]
h2 = [[1, 1], [1, -1]]
for i in range(m - 1):
if i == 0:
h = np.kron(h2, h2)
else:
h = np.kron(h, h2)
return np.dot(h, x) / 2. ** m
arr = [1.0, 1.0, 1.0, 2.0, 0.0, 0.0, 0.0, 0.0]
print(walsh_transform(arr))
它返回输出[ 0.625 -0.125 -0.125 0.125 0.625 -0.125 -0.125 0.125]
如何让它返回输出 [0.625, -0.125, -0.125, 0.125, 0.625, -0.125, -0.125, 0.125] ? IE。逗号分隔值?
【问题讨论】:
-
我个人的意见是,你应该明确地说你想要一个列表形式的输出,而不是让读者仔细检查你的实际和期望的输出,看看有什么不同。我可能只是不注意,但我花了一些阅读才能看到它。
-
希望我们能够为您提供帮助。如果是这样,请将使用的答案标记为正确:) 祝你有美好的一天!
标签: python python-3.x function numpy