Suppose we need to convert array members to integers in an old-fashioned way via a for loop (not as x.astype(int)) : import numpy as np x = np.array([[ 2016., 1., 1.], [ 2016., 12., 31.]]) x array([[ 2.01600000e+03, 1.00000000e+00, 1.00000000e+00], [ 2.01600000e+03, 1.20000000e+01, 3.10000000e+01]]) In a for loop this would have been achieved as: y…

  List comprehensions are an easy way to make a list out of another list. For example:   list1 = [1, 2, 3, 4, 5, 6] print(list1) list2 = [x**2 for x in list1] print(list2) [1, 2, 3, 4, 5, 6][1, 4, 9, 16, 25, 36]   A similar construct exists for dictionaries and is…

© 2014 In R we trust.
Top
Follow us: