|
27 | 27 | "1. Inspecting an array with slicing and indexing" |
28 | 28 | ] |
29 | 29 | }, |
30 | | - { |
31 | | - "cell_type": "markdown", |
32 | | - "metadata": {}, |
33 | | - "source": [ |
34 | | - "## Prerequisites\n", |
35 | | - "\n", |
36 | | - "| Concepts | Importance | Notes |\n", |
37 | | - "| --- | --- | --- |\n", |
38 | | - "| [Python Quickstart](../../foundations/quickstart) | Necessary | Lists, indexing, slicing, math |\n", |
39 | | - "\n", |
40 | | - "* **Time to learn**: 35 minutes\n", |
41 | | - "---" |
42 | | - ] |
43 | | - }, |
44 | 30 | { |
45 | 31 | "cell_type": "markdown", |
46 | 32 | "metadata": {}, |
47 | 33 | "source": [ |
48 | 34 | "## Imports\n", |
49 | | - "A common convention you might encounter is to rename `numpy` to `np` on import to shorten it for the many times we will be calling on `numpy` for functionality." |
| 35 | + "You need to import packages into your notebook to be able to use them. A common convention you might encounter is to rename `numpy` to `np` on import to shorten it for the many times we will be calling on `numpy` for functionality." |
50 | 36 | ] |
51 | 37 | }, |
52 | 38 | { |
53 | 39 | "cell_type": "code", |
54 | | - "execution_count": null, |
| 40 | + "execution_count": 1, |
55 | 41 | "metadata": {}, |
56 | 42 | "outputs": [], |
57 | 43 | "source": [ |
|
64 | 50 | "source": [ |
65 | 51 | "## Create an array of 'data'\n", |
66 | 52 | "\n", |
67 | | - "The NumPy array represents a *contiguous* block of memory, holding entries of a given type (and hence fixed size). The entries are laid out in memory according to the shape, or list of dimension sizes. Let's start by creating an array from a list of integers and taking a look at it," |
| 53 | + "The NumPy array represents a *contiguous* block of memory, holding entries of a given type (and hence fixed size). Let's start by creating an array from a list of integers and taking a look at it," |
68 | 54 | ] |
69 | 55 | }, |
70 | 56 | { |
71 | 57 | "cell_type": "code", |
72 | | - "execution_count": null, |
73 | | - "metadata": {}, |
74 | | - "outputs": [], |
| 58 | + "execution_count": 2, |
| 59 | + "metadata": {}, |
| 60 | + "outputs": [ |
| 61 | + { |
| 62 | + "data": { |
| 63 | + "text/plain": [ |
| 64 | + "array([1, 2, 3])" |
| 65 | + ] |
| 66 | + }, |
| 67 | + "execution_count": 2, |
| 68 | + "metadata": {}, |
| 69 | + "output_type": "execute_result" |
| 70 | + } |
| 71 | + ], |
75 | 72 | "source": [ |
76 | 73 | "a = np.array([1, 2, 3])\n", |
77 | 74 | "a" |
|
81 | 78 | "cell_type": "markdown", |
82 | 79 | "metadata": {}, |
83 | 80 | "source": [ |
84 | | - "We can inspect the number of dimensions our array is organized along with `ndim`, and how long each of these dimensions are with `shape`" |
| 81 | + "The entries of the array are laid out in memory according to the shape, or list of dimension sizes. We can inspect the number of dimensions of our array with `ndim`, and how long each of these dimensions are with `shape`. " |
85 | 82 | ] |
86 | 83 | }, |
87 | 84 | { |
88 | 85 | "cell_type": "code", |
89 | | - "execution_count": null, |
90 | | - "metadata": {}, |
91 | | - "outputs": [], |
| 86 | + "execution_count": 3, |
| 87 | + "metadata": {}, |
| 88 | + "outputs": [ |
| 89 | + { |
| 90 | + "data": { |
| 91 | + "text/plain": [ |
| 92 | + "1" |
| 93 | + ] |
| 94 | + }, |
| 95 | + "execution_count": 3, |
| 96 | + "metadata": {}, |
| 97 | + "output_type": "execute_result" |
| 98 | + } |
| 99 | + ], |
92 | 100 | "source": [ |
93 | 101 | "a.ndim" |
94 | 102 | ] |
95 | 103 | }, |
96 | 104 | { |
97 | 105 | "cell_type": "code", |
98 | | - "execution_count": null, |
99 | | - "metadata": {}, |
100 | | - "outputs": [], |
| 106 | + "execution_count": 4, |
| 107 | + "metadata": {}, |
| 108 | + "outputs": [ |
| 109 | + { |
| 110 | + "data": { |
| 111 | + "text/plain": [ |
| 112 | + "(3,)" |
| 113 | + ] |
| 114 | + }, |
| 115 | + "execution_count": 4, |
| 116 | + "metadata": {}, |
| 117 | + "output_type": "execute_result" |
| 118 | + } |
| 119 | + ], |
101 | 120 | "source": [ |
102 | 121 | "a.shape" |
103 | 122 | ] |
|
106 | 125 | "cell_type": "markdown", |
107 | 126 | "metadata": {}, |
108 | 127 | "source": [ |
109 | | - "So our 1-dimensional array has a shape of `3` along that dimension! Finally we can check out the underlying type of our underlying data," |
| 128 | + "So our 1-dimensional array has a shape of `3` along that dimension! The dot `(.)` notation helps you access various `properties` of the NumPy array. Finally, we can check out the underlying type of our underlying data," |
110 | 129 | ] |
111 | 130 | }, |
112 | 131 | { |
113 | 132 | "cell_type": "code", |
114 | | - "execution_count": null, |
115 | | - "metadata": {}, |
116 | | - "outputs": [], |
| 133 | + "execution_count": 5, |
| 134 | + "metadata": {}, |
| 135 | + "outputs": [ |
| 136 | + { |
| 137 | + "data": { |
| 138 | + "text/plain": [ |
| 139 | + "dtype('int64')" |
| 140 | + ] |
| 141 | + }, |
| 142 | + "execution_count": 5, |
| 143 | + "metadata": {}, |
| 144 | + "output_type": "execute_result" |
| 145 | + } |
| 146 | + ], |
117 | 147 | "source": [ |
118 | 148 | "a.dtype" |
119 | 149 | ] |
|
127 | 157 | }, |
128 | 158 | { |
129 | 159 | "cell_type": "code", |
130 | | - "execution_count": null, |
131 | | - "metadata": {}, |
132 | | - "outputs": [], |
| 160 | + "execution_count": 6, |
| 161 | + "metadata": {}, |
| 162 | + "outputs": [ |
| 163 | + { |
| 164 | + "data": { |
| 165 | + "text/plain": [ |
| 166 | + "array([[1., 2., 3.],\n", |
| 167 | + " [4., 5., 6.]])" |
| 168 | + ] |
| 169 | + }, |
| 170 | + "execution_count": 6, |
| 171 | + "metadata": {}, |
| 172 | + "output_type": "execute_result" |
| 173 | + } |
| 174 | + ], |
133 | 175 | "source": [ |
134 | 176 | "a = np.array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])\n", |
135 | 177 | "a" |
136 | 178 | ] |
137 | 179 | }, |
138 | 180 | { |
139 | 181 | "cell_type": "code", |
140 | | - "execution_count": null, |
141 | | - "metadata": {}, |
142 | | - "outputs": [], |
| 182 | + "execution_count": 7, |
| 183 | + "metadata": {}, |
| 184 | + "outputs": [ |
| 185 | + { |
| 186 | + "data": { |
| 187 | + "text/plain": [ |
| 188 | + "2" |
| 189 | + ] |
| 190 | + }, |
| 191 | + "execution_count": 7, |
| 192 | + "metadata": {}, |
| 193 | + "output_type": "execute_result" |
| 194 | + } |
| 195 | + ], |
143 | 196 | "source": [ |
144 | 197 | "a.ndim" |
145 | 198 | ] |
146 | 199 | }, |
147 | 200 | { |
148 | 201 | "cell_type": "code", |
149 | | - "execution_count": null, |
150 | | - "metadata": {}, |
151 | | - "outputs": [], |
| 202 | + "execution_count": 8, |
| 203 | + "metadata": {}, |
| 204 | + "outputs": [ |
| 205 | + { |
| 206 | + "data": { |
| 207 | + "text/plain": [ |
| 208 | + "(2, 3)" |
| 209 | + ] |
| 210 | + }, |
| 211 | + "execution_count": 8, |
| 212 | + "metadata": {}, |
| 213 | + "output_type": "execute_result" |
| 214 | + } |
| 215 | + ], |
152 | 216 | "source": [ |
153 | 217 | "a.shape" |
154 | 218 | ] |
155 | 219 | }, |
156 | 220 | { |
157 | 221 | "cell_type": "code", |
158 | | - "execution_count": null, |
159 | | - "metadata": {}, |
160 | | - "outputs": [], |
| 222 | + "execution_count": 9, |
| 223 | + "metadata": {}, |
| 224 | + "outputs": [ |
| 225 | + { |
| 226 | + "data": { |
| 227 | + "text/plain": [ |
| 228 | + "dtype('float64')" |
| 229 | + ] |
| 230 | + }, |
| 231 | + "execution_count": 9, |
| 232 | + "metadata": {}, |
| 233 | + "output_type": "execute_result" |
| 234 | + } |
| 235 | + ], |
161 | 236 | "source": [ |
162 | 237 | "a.dtype" |
163 | 238 | ] |
|
0 commit comments