0
How can I write the section of the for (bucle) in one line? Help me š„¹
import numpy def elements_vector_true(): A, B = numpy.random.randint(10, size = 10), numpy.random.randint(10, size = 10)%2==0 print(f"Vector A: {A}") print(f"Vector B: {B}\n") i, C = 0, [] print("The vector A elements wich position of the vector B elements are true are:") for element in B: if element: C.append(A[i]) i +=1 print(C) elements_vector_true() #This's the code complete. I hope you help me, and if it cannot, also thanks š My code: https://code.sololearn.com/cOcRd5u4gEMO/?ref=app
1 Answer
+ 1
import numpy
def elements_vector_true():
A, B = numpy.random.randint(10, size = 10), numpy.random.randint(10, size = 10)%2==0
print(f"Vector A: {A}")
print(f"Vector B: {B}\n")
print("The vector A elements wich position of the vector B elements are true are:")
C = [A[i] for i, v in enumerate(B) if v]
print(C)
elements_vector_true()