iT邦幫忙

2021 iThome 鐵人賽

DAY 2
0
AI & Data

30Day 從一介凡人羽化成資料科學初學者系列 第 2

Day2 - numpy(1)基本介紹及使用

numpy介紹:

一個可操作高維度陣列的套件,可快速的對整個資料做運算。
就不多說了,讓我們直接實際操作從中認識numpy吧!

首先要使用一個套件,最一開始就是import

import numpy as np

通常我們在用numpy時都會將它命名為np,就是上述程式碼中的 as np

建立ndarray:

使用numpy的array,參數可接受任何序列物件
https://ithelp.ithome.com.tw/upload/images/20210823/20140416oK0k8hJC3l.png
也可將物件直接放入參數

test_list=[ [ [1,'two',3] , ['one',2,'three'] ] , [ [4,'five',6] , ['four',5,'six'] ] ]
d=np.array(test_list)

查看ndarray shape:
https://ithelp.ithome.com.tw/upload/images/20210823/20140416lzHNzxxCk9.png
shape後可加入索引
https://ithelp.ithome.com.tw/upload/images/20210823/20140416Buk1z3s1h9.png

查看ndarray dimension:
https://ithelp.ithome.com.tw/upload/images/20210823/20140416tQEUNycebI.png

查看ndarray裡的資料型態
https://ithelp.ithome.com.tw/upload/images/20210823/20140416fQyxmNN1mz.png

可在建立ndarray使指定好型態
https://ithelp.ithome.com.tw/upload/images/20210823/201404164jubU0anQI.png

astype改變型態

https://ithelp.ithome.com.tw/upload/images/20210823/20140416LUJV4qMf2m.png

今天焦點整理:

學會numpy建立多維陣列
認識其屬性shape、ndim、dtype

送上colab連結,可自行在上面多做點練習更加熟悉numpy
https://colab.research.google.com/drive/1aIRaRvB1HFxFpDTpLNlkUnXJ1ef_4KkH?usp=sharing


上一篇
Day1 - 導讀 帶你認識資料科學所需套件
下一篇
Day3 - numpy(2) 基本索引
系列文
30Day 從一介凡人羽化成資料科學初學者30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言