1import numpy as np
2my_list = [2,4,6,8,10]
3my_array = np.array(my_list)
4# printing my_array
5print my_array
6# printing the type of my_array
7print type(my_array)
1# importing library
2import numpy
3
4# initilizing list
5lst = [1, 7, 0, 6, 2, 5, 6]
6
7# converting list to array
8arr = numpy.array(lst)
9
10# displaying list
11print ("List: ", lst)
12
13# displaying array
14print ("Array: ", arr)
1# Basic syntax:
2numpy.array(list_of_lists)
3
4# Example usage:
5import numpy as np
6list_of_lists = [[1, 2, 3], [4, 5, 6]] # Create list of lists
7your_array = np.array(list_of_lists) # Convert list of lists to array
8your_array
9--> array([[1, 2, 3],
10 [4, 5, 6]])
1def tips_unfold(fn, seed):
2 def fn_generator(val):
3 while True:
4 val = fn(val[1])
5 if val == False: break
6 yield val[0]
7 return [i for i in fn_generator([None, seed])]
8
9f = lambda n: False if n > 50 else [-n, n + 10]
10print(tips_unfold(f, 10))
11