NumPy百題(二)

上一篇:NumPy百題(一)

21. Create a checkerboard 8x8 matrix using the tile function

使用tile函數創建8*8的棋盤矩陣
在這裏插入圖片描述

tile函數

tile函數是模板numpy.lib.shape_base中的函數。
函數的形式是tile(A,reps)
A的類型幾乎所有類型都可以:array, list, tuple, dict, matrix以及基本數據類型int, string, float以及bool類型。
reps的類型也很多,可以是tuple,list, dict, array, int,bool.但不可以是float, string, matrix類型。行列重複copy的次數。
在這裏插入圖片描述

22. Normalize a 5x5 random matrix

對一個5*5矩陣標準化處理
在這裏插入圖片描述

矩陣標準化

矩陣標準化的目的是,通過標準化處理,得到均值爲0,標準差爲1的服從標準正態分佈的數據。(相對一維數據來說,也就是相對矩陣的每一列,數據的每一個維度)
矩陣標準化方法是樣本數據減去均值(mean)然後除以標準差(std)。

23. Create a custom dtype that describes a color as four unsigned bytes (RGBA)

新建一個dtype類型用來描述一個顏色(RGBA)
在這裏插入圖片描述

24. Multiply a 5x3 matrix by a 3x2 matrix

53矩陣和32矩陣相乘
在這裏插入圖片描述

25. Given a 1D array, negate all elements which are between 3 and 8, in place

給定一個一維數組,將第3~8個元素取反
在這裏插入圖片描述

26. What is the output of the following script

看看下面腳本的輸出是什麼
在這裏插入圖片描述

27. Consider an integer vector Z, which of these expressions are legal

給定一個整數數組Z,看看下面哪個表達式是合法的
在這裏插入圖片描述

28. What are the result of the following expressions

下面表達式的結果是什麼
在這裏插入圖片描述

29. How to round away from zero a float array

如何對數組進行四捨五入操作

在這裏插入圖片描述

30. How to find common values between two arrays

如何找出兩個數組的共同值
在這裏插入圖片描述

31. How to ignore all numpy warnings (not recommended)

如何忽略所有numpy警告
在這裏插入圖片描述

32. Is the following expressions true

下面表達式正確嗎
在這裏插入圖片描述

33. How to get the dates of yesterday, today and tomorrow

如何獲得昨天、今天、明天的日期
在這裏插入圖片描述

34. How to get all the dates corresponding to the month of July 2016

如何獲得2016年7月對應的所有日期
在這裏插入圖片描述

35. How to compute ((A+B)*(-A/2)) in place (without copy)

如何計算((A+B)*(-A/2))
在這裏插入圖片描述

36. Extract the integer part of a random array using 5 different methods

提取隨機數列整數部分的五種方法
在這裏插入圖片描述

37. Create a 5x5 matrix with row values ranging from 0 to 4

創建一個5*5的矩陣,每一行值爲1~4
在這裏插入圖片描述

38. Consider a generator function that generates 10 integers and use it to build an array

給定一個生成器函數,可以生成10個整數,使用它來創建一個數組

在這裏插入圖片描述

39. Create a vector of size 10 with values ranging from 0 to 1, both excluded

創建一個長度爲10的數組,值爲0~1之間,不包含首尾
在這裏插入圖片描述

np.linspace主要用來創建等差數列。

numpy.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None, axis=0)

start:返回樣本數據開始點
stop:返回樣本數據結束點
num:生成的樣本數據量,默認爲50
endpoint:True則包含stop;False則不包含stop
retstep:If True, return (samples, step), where step is the spacing between samples.(即如果爲True則結果會給出數據間隔)
dtype:輸出數組類型
axis:0(默認)或-1

40. Create a random vector of size 10 and sort it

創建一個長度爲10的數組,並做排序操作
在這裏插入圖片描述

++++++++++++++++++++++++++++++++++++

下一篇:NumPy百題(三)

發佈了82 篇原創文章 · 獲贊 122 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章