chapter 4 NumPy Basics: Arrays and Vectorized Computation

4.1 The NumPy ndarray: A Multidimensional Array Object

Creating ndarrays

Array creation functions.png

Data Types for ndarrays

NumPy data types.png

np.astype 轉(zhuǎn)換類型

Fancy Indexing

Transposing Arrays and Swapping Axes

ndarray.T
numpy.transpose

https://blog.csdn.net/Hearthougan/article/details/72626643
剛開始看這些數(shù)據(jù),根本沒有頭緒,這就要理解transpose()中的參數(shù)的意義,因?yàn)閿?shù)組a的shape為(2,3,5),是一個(gè)三維數(shù)組,那么這個(gè)元組對(duì)應(yīng)的索引為:(0,1,2),也就是a.shape的下標(biāo):(2[0], 3[1], 5[2]), []中對(duì)應(yīng)的是shape元組的索引。那么,現(xiàn)在,通過b = a.transpose(1, 0, 2),那么b.shape就變成(3, 2, 5),這就是說transpose就是改變高維數(shù)組的形狀,形狀改變了,那么里面的元素自然也要重新排列,比如:元素11在a中的位置是a[0][2][1],經(jīng)過b = a.transpose(1, 0, 2)之后,11在b中的位置就變成b[2][0][1]。再比如元素28,在a中的位置a[1][2][3],在b中為:a[2][1][3].

numpy.swapaxes

example: arr.swapaxes(2,1) #就是將第三個(gè)維度和第二個(gè)維度交換

4.2 Universal Functions: Fast Element-Wise Array Functions

Unary ufuncs.png
Binary universal functions.png

4.3 Array-Oriented Programming with Arrays

Expressing Conditional Logic as Array Operations

np.where(cond, xarr, yarr)等于x if c else y

Mathematical and Statistical Methods

Basic array statistical methods.png

Methods for Boolean Arrays

any tests whether one or more values in an array is True , while all checks if every value is True

Sorting

ndarray.sort(axis=-1, kind='quicksort', order=None)
使用方法:a.sort
參數(shù)說明:
axis:排序沿著數(shù)組的方向,0表示按行,1表示按列
kind:排序的算法,提供了快排、混排、堆排
order:不是指的順序,以后用的時(shí)候再去分析這個(gè)
作用效果:對(duì)數(shù)組a排序,排序后直接改變了a

作者:吃土的司機(jī)
鏈接:http://www.itdecent.cn/p/b4d46c612ae4
來源:簡(jiǎn)書
著作權(quán)歸作者所有。商業(yè)轉(zhuǎn)載請(qǐng)聯(lián)系作者獲得授權(quán),非商業(yè)轉(zhuǎn)載請(qǐng)注明出處。

Unique and Other Set Logic

Array set operations.png

4.4 File Input and Output with Arrays

np.save
np.savez
np.load
np.savez_compressed

4.5 Linear Algebra

Commonly used numpy.linalg functions.png

4.6 Pseudorandom Number Generation

Partial list of numpy.random functions.png
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 基礎(chǔ)篇NumPy的主要對(duì)象是同種元素的多維數(shù)組。這是一個(gè)所有的元素都是一種類型、通過一個(gè)正整數(shù)元組索引的元素表格(...
    oyan99閱讀 5,288評(píng)論 0 18
  • 先決條件 在閱讀這個(gè)教程之前,你多少需要知道點(diǎn)python。如果你想從新回憶下,請(qǐng)看看Python Tutoria...
    舒map閱讀 2,720評(píng)論 1 13
  • NumPy是Python中關(guān)于科學(xué)計(jì)算的一個(gè)類庫(kù),在這里簡(jiǎn)單介紹一下。 來源:https://docs.scipy...
    灰太狼_black閱讀 1,330評(píng)論 0 5
  • 一.NumPy的引入 標(biāo)準(zhǔn)安裝的Python中用列表(list)保存一組值,可以用來當(dāng)作數(shù)組使用,不過由于列...
    wlj1107閱讀 1,133評(píng)論 0 2
  • (2018-01-12-周五 22:54:07) A:⑤你可以在組件上使用右鍵,選擇相應(yīng)的菜單功能編輯組件
    菜五閱讀 310評(píng)論 0 0

友情鏈接更多精彩內(nèi)容