0

我有以下代码

a_alpha_beta = zeros((2,  len( atime ) ))

for i in range( len( atime ) ):        
        alpha_beta = transf.clarke(signal[0][i], signal[1][i], signal[2][i])
        a_alpha_beta[0][i] = alpha_beta[0][0] 
        a_alpha_beta[1][i] = alpha_beta[1][0]

如何优化上面的代码,例如如何复制alpha_betaa_alpha_beta

4

1 回答 1

1

我不完全知道函数 transf.clarke 的作用,但是您可以按如下方式完成您想要的复制操作:

import numpy as np

# generate a test input
x = np.arange(0, 10).reshape((2, 5))
print x

# simply copy 2d array
y = x.copy()
print y

# some new data (i.e., alpha_beta in the original code)
z = np.array([[10, 11, 12],
              [13, 14, 15]])
print z

# replace the iteration by numpy slicing to obtain the same result
x[0, :] = z[0, 0]
x[1, :] = z[1, 0]
print x
于 2012-09-09T19:17:16.860 回答