Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 30921c7

Browse files
author
craigsdennis
committed
Added students_gpas for multi-dimensional array example
1 parent 7fa174b commit 30921c7

File tree

1 file changed

+242
-0
lines changed

1 file changed

+242
-0
lines changed

‎Introduction to NumPy.ipynb

Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,248 @@
211211
"gpas.nbytes"
212212
]
213213
},
214+
{
215+
"cell_type": "code",
216+
"execution_count": 24,
217+
"metadata": {},
218+
"outputs": [
219+
{
220+
"data": {
221+
"text/plain": [
222+
"array([[4. , 3.285, 3.5 , 4. ],\n",
223+
" [3.2 , 3.8 , 4. , 4. ],\n",
224+
" [3.96 , 3.92 , 4. , 4. ]], dtype=float16)"
225+
]
226+
},
227+
"execution_count": 24,
228+
"metadata": {},
229+
"output_type": "execute_result"
230+
}
231+
],
232+
"source": [
233+
"students_gpas = np.array([\n",
234+
" [4.0, 3.286, 3.5, 4.0],\n",
235+
" [3.2, 3.8, 4.0, 4.0],\n",
236+
" [3.96, 3.92, 4.0, 4.0]\n",
237+
"], np.float16)\n",
238+
"students_gpas"
239+
]
240+
},
241+
{
242+
"cell_type": "code",
243+
"execution_count": 25,
244+
"metadata": {},
245+
"outputs": [
246+
{
247+
"data": {
248+
"text/plain": [
249+
"2"
250+
]
251+
},
252+
"execution_count": 25,
253+
"metadata": {},
254+
"output_type": "execute_result"
255+
}
256+
],
257+
"source": [
258+
"students_gpas.ndim"
259+
]
260+
},
261+
{
262+
"cell_type": "code",
263+
"execution_count": 26,
264+
"metadata": {},
265+
"outputs": [
266+
{
267+
"data": {
268+
"text/plain": [
269+
"(3, 4)"
270+
]
271+
},
272+
"execution_count": 26,
273+
"metadata": {},
274+
"output_type": "execute_result"
275+
}
276+
],
277+
"source": [
278+
"students_gpas.shape"
279+
]
280+
},
281+
{
282+
"cell_type": "code",
283+
"execution_count": 27,
284+
"metadata": {},
285+
"outputs": [
286+
{
287+
"data": {
288+
"text/plain": [
289+
"12"
290+
]
291+
},
292+
"execution_count": 27,
293+
"metadata": {},
294+
"output_type": "execute_result"
295+
}
296+
],
297+
"source": [
298+
"students_gpas.size"
299+
]
300+
},
301+
{
302+
"cell_type": "code",
303+
"execution_count": 28,
304+
"metadata": {},
305+
"outputs": [
306+
{
307+
"data": {
308+
"text/plain": [
309+
"3"
310+
]
311+
},
312+
"execution_count": 28,
313+
"metadata": {},
314+
"output_type": "execute_result"
315+
}
316+
],
317+
"source": [
318+
"len(students_gpas)"
319+
]
320+
},
321+
{
322+
"cell_type": "code",
323+
"execution_count": 29,
324+
"metadata": {},
325+
"outputs": [
326+
{
327+
"data": {
328+
"text/plain": [
329+
"2"
330+
]
331+
},
332+
"execution_count": 29,
333+
"metadata": {},
334+
"output_type": "execute_result"
335+
}
336+
],
337+
"source": [
338+
"students_gpas.itemsize"
339+
]
340+
},
341+
{
342+
"cell_type": "code",
343+
"execution_count": 30,
344+
"metadata": {},
345+
"outputs": [
346+
{
347+
"data": {
348+
"text/plain": [
349+
"24"
350+
]
351+
},
352+
"execution_count": 30,
353+
"metadata": {},
354+
"output_type": "execute_result"
355+
}
356+
],
357+
"source": [
358+
"students_gpas.itemsize * students_gpas.size"
359+
]
360+
},
361+
{
362+
"cell_type": "code",
363+
"execution_count": 31,
364+
"metadata": {},
365+
"outputs": [
366+
{
367+
"name": "stdout",
368+
"output_type": "stream",
369+
"text": [
370+
"Variable Type Data/Info\n",
371+
"------------------------------------\n",
372+
"gpas ndarray 4: 4 elems, type `float64`, 32 bytes\n",
373+
"students_gpas ndarray 3x4: 12 elems, type `float16`, 24 bytes\n",
374+
"study_minutes ndarray 100: 100 elems, type `uint16`, 200 bytes\n"
375+
]
376+
}
377+
],
378+
"source": [
379+
"%whos ndarray"
380+
]
381+
},
382+
{
383+
"cell_type": "code",
384+
"execution_count": 32,
385+
"metadata": {},
386+
"outputs": [
387+
{
388+
"name": "stdout",
389+
"output_type": "stream",
390+
"text": [
391+
"class: ndarray\n",
392+
"shape: (3, 4)\n",
393+
"strides: (8, 2)\n",
394+
"itemsize: 2\n",
395+
"aligned: True\n",
396+
"contiguous: True\n",
397+
"fortran: False\n",
398+
"data pointer: 0x7fb7c53ee240\n",
399+
"byteorder: little\n",
400+
"byteswap: False\n",
401+
"type: float16\n"
402+
]
403+
}
404+
],
405+
"source": [
406+
"np.info(students_gpas)"
407+
]
408+
},
409+
{
410+
"cell_type": "code",
411+
"execution_count": 33,
412+
"metadata": {},
413+
"outputs": [
414+
{
415+
"data": {
416+
"text/plain": [
417+
"array([3.96, 3.92, 4. , 4. ], dtype=float16)"
418+
]
419+
},
420+
"execution_count": 33,
421+
"metadata": {},
422+
"output_type": "execute_result"
423+
}
424+
],
425+
"source": [
426+
"students_gpas[2]"
427+
]
428+
},
429+
{
430+
"cell_type": "code",
431+
"execution_count": 34,
432+
"metadata": {},
433+
"outputs": [
434+
{
435+
"data": {
436+
"text/plain": [
437+
"4.0"
438+
]
439+
},
440+
"execution_count": 34,
441+
"metadata": {},
442+
"output_type": "execute_result"
443+
}
444+
],
445+
"source": [
446+
"students_gpas[2][3]"
447+
]
448+
},
449+
{
450+
"cell_type": "code",
451+
"execution_count": null,
452+
"metadata": {},
453+
"outputs": [],
454+
"source": []
455+
},
214456
{
215457
"cell_type": "markdown",
216458
"metadata": {},

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /