|
8 | 8 | "source": [ |
9 | 9 | "import numpy as np\n", |
10 | 10 | "import torch\n", |
11 | | - "torch.set_printoptions(edgeitems=2, threshold=50)" |
| 11 | + "torch.set_printoptions(edgeitems=2, threshold=50, linewidth=75)" |
12 | 12 | ] |
13 | 13 | }, |
14 | 14 | { |
|
32 | 32 | } |
33 | 33 | ], |
34 | 34 | "source": [ |
35 | | - "bikes_numpy = np.loadtxt(\"../data/p1ch4/bike-sharing-dataset/hour-fixed.csv\", \n", |
36 | | - " dtype=np.float32, \n", |
37 | | - " delimiter=\",\", \n", |
38 | | - " skiprows=1, \n", |
39 | | - " converters={1: lambda x: float(x[8:10])}) # <1>\n", |
| 35 | + "bikes_numpy = np.loadtxt(\n", |
| 36 | + " \"../data/p1ch4/bike-sharing-dataset/hour-fixed.csv\", \n", |
| 37 | + " dtype=np.float32, \n", |
| 38 | + " delimiter=\",\", \n", |
| 39 | + " skiprows=1, \n", |
| 40 | + " converters={1: lambda x: float(x[8:10])}) # <1>\n", |
40 | 41 | "bikes = torch.from_numpy(bikes_numpy)\n", |
41 | 42 | "bikes" |
42 | 43 | ] |
|
113 | 114 | { |
114 | 115 | "data": { |
115 | 116 | "text/plain": [ |
116 | | - "tensor([1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 2, 2, 2, 2])" |
| 117 | + "tensor([1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 2, 2,\n", |
| 118 | + " 2, 2])" |
117 | 119 | ] |
118 | 120 | }, |
119 | 121 | "execution_count": 6, |
|
162 | 164 | { |
163 | 165 | "data": { |
164 | 166 | "text/plain": [ |
165 | | - "tensor([[ 1.0000, 1.0000, 1.0000, 0.0000, 1.0000, 0.0000, 0.0000, 6.0000,\n", |
166 | | - " 0.0000, 1.0000, 0.2400, 0.2879, 0.8100, 0.0000, 3.0000, 13.0000,\n", |
167 | | - " 16.0000, 1.0000, 0.0000, 0.0000, 0.0000]])" |
| 167 | + "tensor([[ 1.0000, 1.0000, 1.0000, 0.0000, 1.0000, 0.0000, 0.0000,\n", |
| 168 | + " 6.0000, 0.0000, 1.0000, 0.2400, 0.2879, 0.8100, 0.0000,\n", |
| 169 | + " 3.0000, 13.0000, 16.0000, 1.0000, 0.0000, 0.0000, 0.0000]])" |
168 | 170 | ] |
169 | 171 | }, |
170 | 172 | "execution_count": 8, |
|
193 | 195 | } |
194 | 196 | ], |
195 | 197 | "source": [ |
196 | | - "daily_weather_onehot = torch.zeros(daily_bikes.shape[0], 4, daily_bikes.shape[2])\n", |
| 198 | + "daily_weather_onehot = torch.zeros(daily_bikes.shape[0], 4,\n", |
| 199 | + " daily_bikes.shape[2])\n", |
197 | 200 | "daily_weather_onehot.shape" |
198 | 201 | ] |
199 | 202 | }, |
|
214 | 217 | } |
215 | 218 | ], |
216 | 219 | "source": [ |
217 | | - "daily_weather_onehot.scatter_(1, daily_bikes[:,9,:].long().unsqueeze(1) - 1, 1.0)\n", |
| 220 | + "daily_weather_onehot.scatter_(\n", |
| 221 | + " 1, daily_bikes[:,9,:].long().unsqueeze(1) - 1, 1.0)\n", |
218 | 222 | "daily_weather_onehot.shape" |
219 | 223 | ] |
220 | 224 | }, |
|
245 | 249 | "temp = daily_bikes[:, 10, :]\n", |
246 | 250 | "temp_min = torch.min(temp)\n", |
247 | 251 | "temp_max = torch.max(temp)\n", |
248 | | - "daily_bikes[:, 10, :] = (daily_bikes[:, 10, :] - temp_min) / (temp_max - temp_min)" |
| 252 | + "daily_bikes[:, 10, :] = ((daily_bikes[:, 10, :] - temp_min)\n", |
| 253 | + " / (temp_max - temp_min))" |
249 | 254 | ] |
250 | 255 | }, |
251 | 256 | { |
|
255 | 260 | "outputs": [], |
256 | 261 | "source": [ |
257 | 262 | "temp = daily_bikes[:, 10, :]\n", |
258 | | - "daily_bikes[:, 10, :] = (daily_bikes[:, 10, :] - torch.mean(temp)) / torch.std(temp)" |
| 263 | + "daily_bikes[:, 10, :] = ((daily_bikes[:, 10, :] - torch.mean(temp))\n", |
| 264 | + " / torch.std(temp))" |
259 | 265 | ] |
260 | 266 | } |
261 | 267 | ], |
|
275 | 281 | "name": "python", |
276 | 282 | "nbconvert_exporter": "python", |
277 | 283 | "pygments_lexer": "ipython3", |
278 | | - "version": "3.6.6" |
| 284 | + "version": "3.7.6" |
279 | 285 | } |
280 | 286 | }, |
281 | 287 | "nbformat": 4, |
|
0 commit comments