NumPy百题(二)

上一篇:NumPy百题(一)

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

使用tile函数创建8*8的棋盘矩阵
NumPy百题(二)

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的次数。
NumPy百题(二)

22. Normalize a 5x5 random matrix

对一个5*5矩阵标准化处理
NumPy百题(二)

矩阵标准化

矩阵标准化的目的是,通过标准化处理,得到均值为0,标准差为1的服从标准正态分布的数据。(相对一维数据来说,也就是相对矩阵的每一列,数据的每一个维度)
矩阵标准化方法是样本数据减去均值(mean)然后除以标准差(std)。

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

新建一个dtype类型用来描述一个颜色(RGBA)
NumPy百题(二)

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

53矩阵和32矩阵相乘
NumPy百题(二)

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

给定一个一维数组,将第3~8个元素取反
NumPy百题(二)

26. What is the output of the following script

看看下面脚本的输出是什么
NumPy百题(二)

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

给定一个整数数组Z,看看下面哪个表达式是合法的
NumPy百题(二)

28. What are the result of the following expressions

下面表达式的结果是什么
NumPy百题(二)

29. How to round away from zero a float array

如何对数组进行四舍五入操作

NumPy百题(二)

30. How to find common values between two arrays

如何找出两个数组的共同值
NumPy百题(二)

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

如何忽略所有numpy警告
NumPy百题(二)

32. Is the following expressions true

下面表达式正确吗
NumPy百题(二)

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

如何获得昨天、今天、明天的日期
NumPy百题(二)

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

如何获得2016年7月对应的所有日期
NumPy百题(二)

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

如何计算((A+B)*(-A/2))
NumPy百题(二)

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

提取随机数列整数部分的五种方法
NumPy百题(二)

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

创建一个5*5的矩阵,每一行值为1~4
NumPy百题(二)

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

给定一个生成器函数,可以生成10个整数,使用它来创建一个数组

NumPy百题(二)

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

创建一个长度为10的数组,值为0~1之间,不包含首尾
NumPy百题(二)

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

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

下一篇:NumPy百题(三)