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

  • 3
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值