Hello:
I have learned Python for a few days only, so have quite some questions. The following question(s) I want to ask is about the code translation. The original code I had was in F#, but I tried to convert it into Python, it works. But it seems a little ugly, so I want to see if anyone can advise how to improve it. The following is my code:
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
from scipy import stats
import numpy as np
bidcv =
signs =
cvs =
a = [1.0, 2.0, 3.0, 4.0, 5.0]
b = [0.0, 1.0, 2.0, 3.0, 4.0]
c = [0.0, 0.1, 0.2, 0.3, 0.4]
d = np.array(list(zip(a, b, c)))
for d1 in d:
if (d1[2] == 0.0):
bidcv.append(d1[0] - d1[1])
else:
bidcv.append(d1[0])
print(bidcv)
for p1 in b:
if (p1 >= 0.0):
signs.append(1.0)
else:
signs.append(0.0)
print(signs)
cvArray = np.array(list(zip(bidcv, signs)))
for cv1 in cvArray:
cvs.append(cv1[0] * cv1[1])
print(cvs)
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
I have 3 arrays: a, b, c.
I created the 4th array d by zipping all 3 arrays: a, b, c
Using the 4th array d, I want to setup another array bidcv.
The rule for bidcv is: if the third array c's value is 0.0, then the corresponding bidcv value is: value of a minus value of b;
otherwise, the bidcv value is value of array a.
Using the second array b, I want to setup another array signs.
The rule for signs is: if the value of b is 0.0 and more, then the signs value is 1.0; if the value of b is negative, then the signs value is 0.0.
The final array is: cvs, which is made of product of array of signs by array of bidcv.
I want to have improvements in 3 areas:
For all the 3 for loops, I want them to be using either array.map or lambad function or combine of the both.
Please show me your code.
Thanks,
I have learned Python for a few days only, so have quite some questions. The following question(s) I want to ask is about the code translation. The original code I had was in F#, but I tried to convert it into Python, it works. But it seems a little ugly, so I want to see if anyone can advise how to improve it. The following is my code:
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
from scipy import stats
import numpy as np
bidcv =
signs =
cvs =
a = [1.0, 2.0, 3.0, 4.0, 5.0]
b = [0.0, 1.0, 2.0, 3.0, 4.0]
c = [0.0, 0.1, 0.2, 0.3, 0.4]
d = np.array(list(zip(a, b, c)))
for d1 in d:
if (d1[2] == 0.0):
bidcv.append(d1[0] - d1[1])
else:
bidcv.append(d1[0])
print(bidcv)
for p1 in b:
if (p1 >= 0.0):
signs.append(1.0)
else:
signs.append(0.0)
print(signs)
cvArray = np.array(list(zip(bidcv, signs)))
for cv1 in cvArray:
cvs.append(cv1[0] * cv1[1])
print(cvs)
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
I have 3 arrays: a, b, c.
I created the 4th array d by zipping all 3 arrays: a, b, c
Using the 4th array d, I want to setup another array bidcv.
The rule for bidcv is: if the third array c's value is 0.0, then the corresponding bidcv value is: value of a minus value of b;
otherwise, the bidcv value is value of array a.
Using the second array b, I want to setup another array signs.
The rule for signs is: if the value of b is 0.0 and more, then the signs value is 1.0; if the value of b is negative, then the signs value is 0.0.
The final array is: cvs, which is made of product of array of signs by array of bidcv.
I want to have improvements in 3 areas:
For all the 3 for loops, I want them to be using either array.map or lambad function or combine of the both.
Please show me your code.
Thanks,