日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Numpy练习题-锻炼手写机器学习模型的能力

發布時間:2025/3/8 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Numpy练习题-锻炼手写机器学习模型的能力 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Numpy是一個用python實現的科學計算的擴展程序庫,包括:

1、一個強大的N維數組對象Array;

2、比較成熟的(廣播)函數庫;

3、用于整合C/C++和Fortran代碼的工具包;

4、實用的線性代數、傅里葉變換和隨機數生成函數。numpy和稀疏矩陣運算包scipy配合使用更加方便。

NumPy(Numeric Python)提供了許多高級的數值編程工具,如:矩陣數據類型、矢量處理,以及精密的運算庫。專為進行嚴格的數字處理而產生。多為很多大型金融公司使用,以及核心的科學計算組織如:Lawrence Livermore,NASA用其處理一些本來使用C++,Fortran或Matlab等所做的任務。

本文整理了一個Numpy的練習題,總結了Numpy的常用操作,可以測試下自己對Numpy的掌握程度,有答案哦。?

下載地址:

https://github.com/fengdu78/Data-Science-Notes/tree/master/2.numpy/numpy_exercises

試題目錄

  • Array creation routines(數組創建)

  • Array manipulation routines(數組操作)

  • String operations(字符串操作)

  • Numpy-specific help functions(Numpy特定幫助函數)

  • Input and output(輸入和輸出)

  • Linear algebra(線性代數)

  • Discrete Fourier Transform(離散傅里葉變換)

  • Logic functions(邏輯函數)

  • Mathematical functions(數學函數)

  • Random sampling (numpy.random)(隨機抽樣)

  • Set routines(集合操作)

  • Sorting, searching, and counting(排序、搜索和計數)

  • Statistics(統計)

試題內容

試題分為13個練習,每個練習分為兩個ipynb文件,文件名帶_Solutions 的是帶答案的文件,建議初學者先練習下不帶答案的文件,做不出來再看看答案。

試題樣例

Linear algebra

import?numpy?as?np np.__version__ '1.11.2'

Matrix and vector products

Q1. Predict the results of the following code.

x?=?[1,2] y?=?[[4,?1],?[2,?2]] print?np.dot(x,?y) print?np.dot(y,?x) print?np.matmul(x,?y) print?np.inner(x,?y) print?np.inner(y,?x) [8 5] [6 6] [8 5] [6 6] [6 6]

Q2. Predict the results of the following code.

x?=?[[1,?0],?[0,?1]] y?=?[[4,?1],?[2,?2],?[1,?1]] print?np.dot(y,?x) print?np.matmul(y,?x)[[4 1][2 2][1 1]] [[4 1][2 2][1 1]]

Q3. Predict the results of the following code.

x?=?np.array([[1,?4],?[5,?6]]) y?=?np.array([[4,?1],?[2,?2]]) print?np.vdot(x,?y) print?np.vdot(y,?x) print?np.dot(x.flatten(),?y.flatten()) print?np.inner(x.flatten(),?y.flatten()) print?(x*y).sum() 30 30 30 30 30

Q4. Predict the results of the following code.

x?=?np.array(['a',?'b'],?dtype=object) y?=?np.array([1,?2]) print?np.inner(x,?y) print?np.inner(y,?x) print?np.outer(x,?y) print?np.outer(y,?x) abb abb [['a' 'aa']['b' 'bb']] [['a' 'b']['aa' 'bb']]

Decompositions

Q5. Get the lower-trianglular L in the Cholesky decomposition of x and verify it.

x?=?np.array([[4,?12,?-16],?[12,?37,?-43],?[-16,?-43,?98]],?dtype=np.int32) L?=?np.linalg.cholesky(x) print?L assert?np.array_equal(np.dot(L,?L.T.conjugate()),?x) [[ 2. 0. 0.][ 6. 1. 0.][-8. 5. 3.]]

Q6. Compute the qr factorization of x and verify it.

x?=?np.array([[12,?-51,?4],?[6,?167,?-68],?[-4,?24,?-41]],?dtype=np.float32) q,?r?=?np.linalg.qr(x) print?"q=\n",?q,?"\nr=\n",?r assert?np.allclose(np.dot(q,?r),?x) q= [[-0.85714287 0.39428571 0.33142856][-0.42857143 -0.90285712 -0.03428571][ 0.2857143 -0.17142858 0.94285715]] r= [[ -14. -21. 14.][ 0. -175. 70.][ 0. 0. -35.]]

Q7. Factor x by Singular Value Decomposition and verify it.

x?=?np.array([[1,?0,?0,?0,?2],?[0,?0,?3,?0,?0],?[0,?0,?0,?0,?0],?[0,?2,?0,?0,?0]],?dtype=np.float32) U,?s,?V?=?np.linalg.svd(x,?full_matrices=False) print?"U=\n",?U,?"\ns=\n",?s,?"\nV=\n",?v assert?np.allclose(np.dot(U,?np.dot(np.diag(s),?V)),?x)U= [[ 0. 1. 0. 0.][ 1. 0. 0. 0.][ 0. 0. 0. -1.][ 0. 0. 1. 0.]] s= [ 3. 2.23606801 2. 0. ] V= [[ 1. 0. 0.][ 0. 1. 0.][ 0. 0. 1.]]

Matrix eigenvalues

Q8. Compute the eigenvalues and right eigenvectors of x. (Name them eigenvals and eigenvecs, respectively)

x?=?np.diag((1,?2,?3)) eigenvals?=?np.linalg.eig(x)[0] eigenvals_?=?np.linalg.eigvals(x) assert?np.array_equal(eigenvals,?eigenvals_) print?"eigenvalues?are\n",?eigenvals eigenvecs?=?np.linalg.eig(x)[1] print?"eigenvectors?are\n",?eigenvecs eigenvalues are [ 1. 2. 3.] eigenvectors are [[ 1. 0. 0.][ 0. 1. 0.][ 0. 0. 1.]]

Q9. Predict the results of the following code.

print?np.array_equal(np.dot(x,?eigenvecs),?eigenvals?*?eigenvecs) True

Norms and other numbers

Q10. Calculate the Frobenius norm and the condition number of x.

x?=?np.arange(1,?10).reshape((3,?3)) print?np.linalg.norm(x,?'fro') print?np.linalg.cond(x,?'fro') 16.8819430161 4.56177073661e+17

Q11. Calculate the determinant of x.

x?=?np.arange(1,?5).reshape((2,?2)) out1?=?np.linalg.det(x) out2?=?x[0,?0]?*?x[1,?1]?-?x[0,?1]?*?x[1,?0] assert?np.allclose(out1,?out2) print?out1 -2.0

Q12. Calculate the rank of x.

x?=?np.eye(4) out1?=?np.linalg.matrix_rank(x) out2?=?np.linalg.svd(x)[1].size assert?out1?==?out2 print?out14

Q13. Compute the sign and natural logarithm of the determinant of x.

x?=?np.arange(1,?5).reshape((2,?2)) sign,?logdet?=?np.linalg.slogdet(x) det?=?np.linalg.det(x) assert?sign?==?np.sign(det) assert?logdet?==?np.log(np.abs(det)) print?sign,?logdet-1.0 0.69314718056

Q14. Return the sum along the diagonal of x.

x?=?np.eye(4) out1?=?np.trace(x) out2?=?x.diagonal().sum() assert?out1?==?out2 print?out1 4.0

Solving equations and inverting matrices

Q15. Compute the inverse of x.

x?=?np.array([[1.,?2.],?[3.,?4.]]) out1?=?np.linalg.inv(x) assert?np.allclose(np.dot(x,?out1),?np.eye(2)) print?out1[[-2. 1. ][ 1.5 -0.5]]

其他資源

本站還發過不少關于Numpy的資源,歡迎收藏學習:

  • 1.Numpy小抄表

  • 2.Numpy100題

  • 3.AI基礎-Numpy簡易入門

參考

  • 作者:Kyubyong

  • 來源:https://github.com/Kyubyong/numpy_exercises

下載地址:

https://github.com/fengdu78/Data-Science-Notes/tree/master/2.numpy/numpy_exercises

往期精彩回顧適合初學者入門人工智能的路線及資料下載機器學習及深度學習筆記等資料打印機器學習在線手冊深度學習筆記專輯《統計學習方法》的代碼復現專輯 AI基礎下載機器學習的數學基礎專輯 獲取本站知識星球優惠券,復制鏈接直接打開: https://t.zsxq.com/y7uvZF6 本站qq群704220115。加入微信群請掃碼: 與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的Numpy练习题-锻炼手写机器学习模型的能力的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 强行挺进白丝老师翘臀网站 | 黄瓜视频污在线观看 | 黄页网站在线 | 欧美精品国产一区二区 | 国产精品17p | 天天干网站 | 疯狂做爰的爽文多肉小说王爷 | 亚洲人高潮女人毛茸茸 | 国产精品二区在线 | 国产老头和老头xxxx× | 黑人玩弄人妻一区二区绿帽子 | 一区二区日韩视频 | 欧美亚洲精品在线 | 无码人妻一区二区三区在线 | 日韩激情精品 | 欧美mv日韩mv国产 | 精品人伦一区二区三区 | 夜夜爽日日澡人人添 | 92精品 | 色一情一伦一子一伦一区 | 波多野结衣视频网址 | 亚洲成人av电影在线 | 少妇久久久 | 99久久久成人国产精品 | 麻豆国产原创 | 污视频免费看 | 天天碰天天干 | 韩国主播青草200vip视频 | 亚洲国产精品久久久久爰性色 | jizz美女| 禁漫天堂黄漫画无遮挡观看 | 影音先锋制服丝袜 | 日本一二区视频 | 校园春色亚洲色图 | 婷婷啪啪 | 久久久三区 | 国产高潮又爽又无遮挡又免费 | 校园激情av| 欧美日韩精品区别 | 欧美日韩色综合 | 夜夜夜夜骑| 中文字幕av一区二区三区谷原希美 | 国产乱人| 久久久久一区 | 欧美乱欲视频 | 黄视频免费观看 | 久久久免费看 | 亚洲午夜久久久久久久国产 | 欧美不卡在线 | 久热99| 亚洲欧美日韩系列 | 欧美黄色性生活 | 伊人久久伊人 | 国产在线一区二 | 中文字字幕在线中文乱码电影 | 国产调教在线 | jizz在亚洲 | 手机看片久久久 | 四虎黄色网 | 亚洲夜夜夜 | 黑人一区二区 | 日韩在线观看视频网站 | 日本少妇裸体做爰 | 欧美一级片在线免费观看 | 欧美抠逼视频 | 中字av在线| 免费观看黄色一级片 | 日韩一区二区三区四区五区 | 亚洲av无一区二区三区 | 午夜免费精品 | 色哟哟一区二区三区 | 精品久久影视 | 日韩激情在线播放 | 在线无码va中文字幕无码 | 日本www网站 | www.x日本| 亚洲成人第一网站 | 在线观看日本 | 亚洲一区二区三区免费看 | 国产秋霞 | 国产成人在线看 | 亚洲综合久久av | 久久精品这里有 | 一本色道久久综合狠狠躁 | 黄页av| 爱如潮水3免费观看日本高清 | 麻豆传媒mv | 96亚洲精品久久久蜜桃 | 国产日本一区二区 | 又黄又爽又刺激的视频 | 毛片在线观看网站 | 欧美一级在线看 | 岛国av免费在线 | 尤物在线免费视频 | 黄色一级一片免费播放 | 91成人国产综合久久精品 | 奇米影视久久 | 清冷学长被爆c躁到高潮失禁 | 一本一道波多野结衣av黑人 |