Hi,
I am learning python. I just saw this coding which is generating 2 datasets.I have a question. Can someone explain the part in "dataset1"? I believe it is a list comprehension.
Mainly I am not understanding what "for child in children" does?
Thanks,
I am learning python. I just saw this coding which is generating 2 datasets.I have a question. Can someone explain the part in "dataset1"? I believe it is a list comprehension.
Mainly I am not understanding what "for child in children" does?
1 2 3 4 5 6 7 8 9 10 11 |
import numpy as np np.random.seed( 10 ) children = range ( 10 ) months = np.arange( 13 ) dataset1 = [ (month, np.dot(month, 24.7 ) + np.random.normal(loc = 0 ,scale = 20 )) for month in months for child in children] month_data = [element[ 0 ] for element in dataset1] # Gets 1st column from data weight_data = [element[ 1 ] for element in dataset1] |