Is this the correct way to declare and iterate through an array in Python, where each element is multiplied by a constant value?
timeArray = array([0]*1000)
for x in timeArray:
timeArray[x] = x * deltaTime
print(timeArray)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
will construct a list with the contents that you want. Indexing into a list takes O(1) time, the same as for an array. Python lists are very fast, they’re actually implemented as arrays.
Are you sure you want to
printthe contents of the array/list while it’s being constructed?(Aside: If you want faster arrays because you’re doing number crunching, then a Numpy array might be a better choice:
)