42 - at least /80-100 times/ faster than lists |
42 - at least /80-100 times/ faster than lists |
43 |
43 |
44 * Creating Arrays |
44 * Creating Arrays |
45 - Creating a 1-dimensional array |
45 - Creating a 1-dimensional array |
46 : In []: a1 = array([1, 2, 3, 4]) |
46 : In []: a1 = array([1, 2, 3, 4]) |
|
47 ~[1, 2, 3, 4]~ is a list. |
|
48 * Creating two-dimensional array |
47 - Creating a 2-dimensional array |
49 - Creating a 2-dimensional array |
48 : In []: a2 = array([[1,2,3,4],[5,6,7,8]]) |
50 : In []: a2 = array([[1,2,3,4],[5,6,7,8]]) |
49 - Easier method of creating array with consecutive elements. |
51 here we convert a list of lists to an array making a 2-d array. |
|
52 - Using ~arange()~ function |
50 : In []: ar = arange(1,9) |
53 : In []: ar = arange(1,9) |
51 * ~reshape()~ method |
54 * ~reshape()~ method |
52 - To reshape an array |
55 - To reshape an array |
53 : In []: ar.reshape(2, 4) |
56 : In []: ar.reshape(2, 4) |
54 : In []: ar.reshape(4, 2) |
57 : In []: ar.reshape(4, 2) |
65 Create a 3-dimensional array of the order (2, 2, 4). |
68 Create a 3-dimensional array of the order (2, 2, 4). |
66 |
69 |
67 * ~.shape~ of array |
70 * ~.shape~ of array |
68 - ~.shape~ |
71 - ~.shape~ |
69 To find the shape of the array |
72 To find the shape of the array |
70 : In []: a1.shape |
73 : In []: a2.shape |
71 - ~.shape~ |
74 - ~.shape~ |
72 returns a tuple of shape |
75 returns a tuple of shape |
73 * Exercise 2 |
76 * Exercise 2 |
74 Find out the shape of the other arrays(a2, a3, ar) that we have created. |
77 Find out the shape of the other arrays(a1, a3, ar) that we have created. |
75 * Homogeneous data |
78 * Homogeneous data |
76 - All elements in array should be of same type |
79 - All elements in array should be of same type |
77 : In []: a4 = array([1,2,3,'a string']) |
80 : In []: a4 = array([1,2,3,'a string']) |
78 * Implicit type casting |
81 * Implicit type casting |
79 : In []: a4 |
82 : In []: a4 |