NumPy百题(三)

上一篇:NumPy百题(二)

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百题(四)

发布了75 篇原创文章 · 获赞 117 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_42893334/article/details/104237210