41. How to sum a small array faster than np.sum
如何對一個數組進行相加操作,並且速度快於np.sum
np.sum和np.add.reduce有什麼區別
42. Consider two random array A and B, check if they are equal
給定兩個隨機數組A和B,驗證它們是否相等
np.allclose
allclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False)
比較兩個array是不是每一元素都相等,默認在1e-05的誤差範圍內。
43. Make an array immutable (read-only)
使一個數組不變(只讀)
44. Consider a random 10x2 matrix representing cartesian coordinates, convert them to polar coordinates
給定表示笛卡爾座標的一個10*2的隨機矩陣,將其轉換爲極座標
45. Create random vector of size 10 and replace the maximum value by 0
創建一個長度爲10的隨機矩陣,並將最大值替換爲0
z.argmax()針對的是非整數的數組進行的最大值檢測
46. Create a structured array with x and y coordinates covering the [0,1]x[0,1] area
創建具有x和y座標的結構化數組,它們覆蓋[0,1] x [0,1]區域
47. Given two arrays, X and Y, construct the Cauchy matrix C (Cij =1/(xi - yj))
給定兩個數組X和Y,構造柯西矩陣C(Cij = 1 /(xi-yj))
48. Print the minimum and maximum representable value for each numpy scalar type
打印每種numpy標量類型的最小和最大可表示值
49. How to print all the values of an array
如何打印數組中所有值
np.set_printoptions(threshold=np.nan)
設置打印時顯示方式。
threshold=np.nan意思是輸出數組的時候完全輸出,不需要省略號將中間數據省略
50. How to find the closest value (to a given scalar) in a vector
如何在數組中找到最接近給定值的值
numpy.random.uniform介紹
函數原型: numpy.random.uniform(low,high,size)
功能:從一個均勻分佈[low,high)中隨機採樣,注意定義域是左閉右開,即包含low,不包含high.
low: 採樣下界,float類型,默認值爲0;
high: 採樣上界,float類型,默認值爲1;
size: 輸出樣本數目,爲int或元組(tuple)類型,例如,size=(m,n,k), 則輸出mnk個樣本,缺省時輸出1個值。
返回值:ndarray類型,其形狀和參數size中描述一致。
51.Create a structured array representing a position (x,y) and a color (r,g,b)
創建一個表示位置(x,y)和顏色(r,g,b)的結構化數組
52.Consider a random vector with shape (100,2) representing coordinates, find point by point distances
對一個表示座標形狀爲(100,2)的隨機向量,找到點與點的距離
53.How to convert a float (32 bits) array into an integer (32 bits) in place
如何將32位的浮點數(float)轉換爲對應的整數(integer)
54.How to read the following file
如何讀取以下文件
55.What is the equivalent of enumerate for numpy arrays
對於numpy數組,enumerate的等價操作是什麼
56.Generate a generic 2D Gaussian-like array
生成一個通用的二維Gaussian-like數組
57.How to randomly place p elements in a 2D array
對一個二維數組,如何在其內部隨機放置p個元素?
58.Subtract the mean of each row of a matrix
減去一個矩陣中的每一行的平均值
59.How to I sort an array by the nth column
如何通過第n列對一個數組進行排序
60.How to tell if a given 2D array has null columns
如何檢查一個二維數組是否有空列
下一篇:NumPy百題(四)