I am trying to convert a python from loop output into an array. For example in the following code, I wanted the output as b = [6.0, 14.0, 0.0, 0.0, 0.0] but it gives the output as a column.
import numpy as np
j = np.arange(1.5, 10.0, 2)
for m in j:
a = 2*m
if a <= 8:
b = 2*a
print(b)
else:
b = 0.0
print(b)
I have tried to define the output b as numpy.array but it does not work. Any idea?
printto not print newlines and add a space. Otherwise, you'd probably want to save the values ofbin a list and in the end print that - or do the whole loop as a list comprehension instead. Do you want to continue processing it later, or do you just care about printing? And will the loop remain this simple?print(a, end=" ")orprint(b, end=" ")