100_Numpy_exercises

ps: 貌似jupyter导出md,图片无法显示及可能出现格式错误,等复盘时再看

资源及学习来自:
numpy-100

这100道练习,带你玩转Numpy

numpy文档

文章目录

知识点简记

#把t中小于10的数字替换为0,把大于10的替换为10
np.where(t<10,0,10) #三元运算符
#把t中小于10的数字替换为0,把大于18的替换为20
t.clip(10,18) #但是nan没有被替换

nan的注意点:
1、两个nan不相等 np.nan!=np.nan
2、判断nan的个数:np.count_nonzero(t!=t)
3、判断是否为nan? np.isnan(a)
nan替换为0:t[np.isnan(t)]=0
4、nan和任何值计算为nan

全部替换为0后,替换之前的平均值如果大于0,替换之后的均值肯定会变小,所以更一般的方式是把缺失的数值替换为均值(中值)或者是直接删除有缺失值的一行

均值:t.mean(a,axis=None) 受离群点的影响较大
中值:np.median(t,axis=None)

100 numpy exercises

This is a collection of exercises that have been collected in the numpy mailing list, on stack overflow
and in the numpy documentation. The goal of this collection is to offer a quick reference for both old
and new users but also to provide a set of exercises for those who teach.

If you find an error or think you’ve a better way to solve some of them, feel
free to open an issue at https://github.com/rougier/numpy-100.

File automatically generated. See the documentation to update questions/answers/hints programmatically.

Run the initialize.py module, then for each question you can query the
answer or an hint with hint(n) or answer(n) for n question number.

%run initialise.py
1. Import the numpy package under the name np (★☆☆)
import numpy as np
2. Print the numpy version and the configuration (★☆☆)
print(np.__version__)
1.20.1
np.show_config
<function numpy.__config__.show()>
3. Create a null vector of size 10 (★☆☆)
x=np.array([10]) #参数是数组
#要加【】才是数组,不加[]只是一个元素
#x=np.array(10) 10
print(x)
[10]
Z = np.zeros(10) #默认生成浮点数,全为0,参数是维度
print(Z)
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
a= np.zeros((2,3)) #必须加括号,不能直接zeros(2,3)
print(a)
[[0. 0. 0.]
 [0. 0. 0.]]
4. How to find the memory size of any array (★☆☆)
print(a.size) #元素个数
print(a.itemsize) #元素大小
print(a.dtype) #float64占8个字节 bites
6
8
float64
print(a.size*a.itemsize) 
48
answer(4)
Z = np.zeros((10,10))
print("%d bytes" % (Z.size * Z.itemsize))
5. How to get the documentation of the numpy add function from the command line? (★☆☆)
np.info(np.add)
6. Create a null vector of size 10 but the fifth value which is 1 (★☆☆)
np.array([0,0,0,0,1,0,0,0,0,0])
array([0, 0, 0, 0, 1, 0, 0, 0, 0, 0])
Z = np.zeros(10)
Z[4] = 1
print(Z)
[0. 0. 0. 0. 1. 0. 0. 0. 0. 0.]
7. Create a vector with values ranging from 10 to 49 (★☆☆)
np.arange(10,50) #左闭右开
array([10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
       27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
       44, 45, 46, 47, 48, 49])
8. Reverse a vector (first element becomes last) (★☆☆)
a=np.array([1,2,3,4,5])
a[::-1] #逆转数组
array([5, 4, 3, 2, 1])
9. Create a 3x3 matrix with values ranging from 0 to 8 (★☆☆)
z=np.arange(0,9)
z.reshape(3,3)
array([[0, 1, 2],
       [3, 4, 5],
       [6, 7, 8]])
10. Find indices索引 of non-zero elements from [1,2,0,0,4,0] (★☆☆)
nz = np.nonzero([1,2,0,0,4,0])
print(nz) #索引,不是元素
(array([0, 1, 4], dtype=int64),)
11. Create a 3x3 identity单位 matrix (★☆☆)
np.eye(3)
array([[1., 0., 0.],
       [0., 1., 0.],
       [0., 0., 1.]])
12. Create a 3x3x3 array with random values (★☆☆)
np.random.random((3,3,3)) # 参数是size
array([[[0.7319371 , 0.84169507, 0.4907933 ],
        [0.44398771, 0.51650912, 0.93462405],
        [0.40676286, 0.51599742, 0.10521164]],

       [[0.99405111, 0.36168199, 0.64296128],
        [0.70033682, 0.73604869, 0.98718712],
        [0.50026776, 0.26253887, 0.52982969]],

       [[0.75480112, 0.79256565, 0.96649806],
        [0.80892628, 0.64277525, 0.62242978],
        [0.79339273, 0.55672428, 0.83845903]]])
13. Create a 10x10 array with random values and find the minimum and maximum values (★☆☆)
x=np.random.random((10,10))
Zmin, Zmax = x.min(), x.max() #注意赋值方式
print(Zmin, Zmax)
0.006560687589317604 0.9925906801963417
14. Create a random vector of size 30 and find the mean value (★☆☆)
x=np.random.random(30)
x.mean()
0.47307002078768357
15. Create a 2d array with 1 on the border and 0 inside (★☆☆)
x=np.ones((10,10))
#学会索引批量改变数值
x[1:9,1:-1]=0 #-1/9代表最后一位,1是第二位 
x
array([[1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
       [1., 0., 0., 0., 0., 0., 0., 0., 0., 1.],
       [1., 0., 0., 0., 0., 0., 0., 0., 0., 1.],
       [1., 0., 0., 0., 0., 0., 0., 0., 0., 1.],
       [1., 0., 0., 0., 0., 0., 0., 0., 0., 1.],
       [1., 0., 0., 0., 0., 0., 0., 0., 0., 1.],
       [1., 0., 0., 0., 0., 0., 0., 0., 0., 1.],
       [1., 0., 0., 0., 0., 0., 0., 0., 0., 1.],
       [1., 0., 0., 0., 0., 0., 0., 0., 0., 1.],
       [1., 1., 1., 1., 1., 1., 1., 1., 1., 1.]])
16. How to add a border (filled with 0’s) around an existing array? (★☆☆)
Z = np.ones((5,5))
Z = np.pad(Z, pad_width=1, mode='constant', constant_values=0)
print(Z)
[[0. 0. 0. 0. 0. 0. 0.]
 [0. 1. 1. 1. 1. 1. 0.]
 [0. 1. 1. 1. 1. 1. 0.]
 [0. 1. 1. 1. 1. 1. 0.]
 [0. 1. 1. 1. 1. 1. 0.]
 [0. 1. 1. 1. 1. 1. 0.]
 [0. 0. 0. 0. 0. 0. 0.]]

https://blog.csdn.net/zenghaitao0128/article/details/78713663

17. What is the result of the following expression? (★☆☆)
0 * np.nan
np.nan == np.nan
np.inf > np.nan
np.nan - np.nan
np.nan in set([np.nan])
0.3 == 3 * 0.1
# NaN = not a number, inf = infinity
print(0 * np.nan)
print(np.nan == np.nan)
print(np.inf > np.nan)
print(np.nan - np.nan)
print(0.3 == 3 * 0.1)
nan
False
False
nan
False
18. Create a 5x5 matrix with values 1,2,3,4 just below the diagonal (★☆☆)
Z = np.diag(1+np.arange(4),k=-1)
print(Z)
[[0 0 0 0 0]
 [1 0 0 0 0]
 [0 2 0 0 0]
 [0 0 3 0 0]
 [0 0 0 4 0]]
Z = np.diag([1,2,3,4],k=-1)
print(Z)
[[0 0 0 0 0]
 [1 0 0 0 0]
 [0 2 0 0 0]
 [0 0 3 0 0]
 [0 0 0 4 0]]

https://blog.csdn.net/The_Time_Runner/article/details/89918383
https://blog.csdn.net/qq_35277038/article/details/80766746

19. Create a 8x8 matrix and fill it with a checkerboard pattern (★☆☆)
Z = np.zeros((8,8),dtype=int)
Z[1::2,::2] = 1
Z[::2,1::2] = 1
print(Z)
[[0 1 0 1 0 1 0 1]
 [1 0 1 0 1 0 1 0]
 [0 1 0 1 0 1 0 1]
 [1 0 1 0 1 0 1 0]
 [0 1 0 1 0 1 0 1]
 [1 0 1 0 1 0 1 0]
 [0 1 0 1 0 1 0 1]
 [1 0 1 0 1 0 1 0]]
20. Consider a (6,7,8) shape array, what is the index (x,y,z) of the 100th element?
print(np.unravel_index(100,(6,7,8))) #第100个数的索引
(1, 5, 4)

https://blog.csdn.net/l1127071087/article/details/89425604
知道一个高维(比如四维)数组中的某个元素,既可以用一个四维向量(a,b,c,d)表示,也可以用一个数字表示,这个数字代表了将高维数组拉伸成一维数组后的索引。

21. Create a checkerboard 8x8 matrix using the tile function (★☆☆)
Z = np.tile( np.array([[0,1],[1,0]]), (4,4))
# Z = np.tile(np.diag([1,1]), (4,4))
print(Z)
[[0 1 0 1 0 1 0 1]
 [1 0 1 0 1 0 1 0]
 [0 1 0 1 0 1 0 1]
 [1 0 1 0 1 0 1 0]
 [0 1 0 1 0 1 0 1]
 [1 0 1 0 1 0 1 0]
 [0 1 0 1 0 1 0 1]
 [1 0 1 0 1 0 1 0]]

https://www.jianshu.com/p/9519f1984c70

22. Normalize a 5x5 random matrix 均值归一化 (★☆☆)
Z = np.random.random((5,5))
Z = (Z - np.mean (Z)) / (np.std (Z))
# Z = (Z - Z.mean()) / (Z.std()) #答案错误???
print(Z)
[[ 0.46968674  1.14937214  1.4132632   1.41694328  0.24617897]
 [-0.96493651  0.24126962 -1.30009156 -1.22291185  0.54047925]
 [-0.65122603 -0.05036635 -1.01305565  0.3694461  -1.13844225]
 [-0.12655212 -1.06133366 -0.88061107  0.67446768  0.36913217]
 [ 0.7562334   1.46487616 -1.03045324  1.8521228  -1.52349122]]
23. Create a custom dtype that describes a color as four unsigned bytes (RGBA) (★☆☆)

创建一个将颜色描述为(RGBA)四个无符号字节的自定义dtype?

color = np.dtype([("r", np.ubyte,  (1,)),
                  ("g", np.ubyte,  (1,)),
                  ("b", np.ubyte,  (1,)),
                  ("a", np.ubyte,  (1,))])
color
dtype([('r', 'u1', (1,)), ('g', 'u1', (1,)), ('b', 'u1', (1,)), ('a', 'u1', (1,))])
answer(23)
color = np.dtype([("r", np.ubyte),
                  ("g", np.ubyte),
                  ("b", np.ubyte),
                  ("a", np.ubyte)])

https://blog.csdn.net/qq_16234613/article/details/65935279

24. Multiply a 5x3 matrix by a 3x2 matrix (real matrix product) (★☆☆)
Z = np.dot(np.ones((5,3)), np.ones((3,2)))
print(Z)
[[3. 3.]
 [3. 3.]
 [3. 3.]
 [3. 3.]
 [3. 3.]]
25. Given a 1D array, negate all elements which are between 3 and 8, in place. (★☆☆)

给定一个一维数组,对其在3到8之间的所有元素取反

Z = np.arange(11)
Z[(3 < Z) & (Z <= 8)] *= -1 #取反为负数
print(Z) 
[ 0  1  2  3 -4 -5 -6 -7 -8  9 10]
26. What is the output of the following script? (★☆☆)
# Author: Jake VanderPlas

print(sum(range(5),-1))
from numpy import *
print(sum(range(5),-1))
print(sum(range(5),-1))
9
from numpy import *
print(sum(range(5),-1))
10

https://stoneboy100200.github.io/2018/08/09/numpy-sum/
python包中sum 第二个参数是指定相加的数字,如在算完range后再加-1
numpy中的sum 第二个参数是维度,-1为最后一个维度,一维不变,直接算完range 结束

27. Consider an integer vector Z, which of these expressions are legal? (★☆☆)
Z**Z
2 << Z >> 2
Z <- Z
1j*Z
Z/1/1
Z<Z>Z
Z = np.arange(5)
Z
array([0, 1, 2, 3, 4])
Z ** Z  # legal
#乘方,0的0次方=1,1的1次方,2的2次方,3的3次方,4的4次方
array([  1,   1,   4,  27, 256], dtype=int32)
2 << Z >> 2 
#左乘 x = x * 2^z
#右乘 x = x / 2^z
#抵消了
array([0, 1, 2, 4, 8], dtype=int32)
Z <- Z #<-X与< (-X)相同 legal
#[0,1,2,3,4]<[0,-1,-2,-3,-4]逐个比较
array([False, False, False, False, False])
1j*Z  #???
array([0.+0.j, 0.+1.j, 0.+2.j, 0.+3.j, 0.+4.j])
Z/1/1 #由整数变成了浮点数
array([0., 1., 2., 3., 4.])
Z<Z>Z # false 
---------------------------------------------------------------------------

ValueError                                Traceback (most recent call last)

<ipython-input-44-0ce43e627203> in <module>
----> 1 Z<Z>Z # false


ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Z<Z
array([False, False, False, False, False])
 0.+1.j
1j
28. What are the result of the following expressions?
np.array(0) / np.array(0)
np.array(0) // np.array(0)
np.array([np.nan]).astype(int).astype(float)
np.array(0) 
array(0)
np.array(0) / np.array(0) #0做了除数?
#等价于np.divide(np.array(0) ,np.array(0) )
<ipython-input-48-d0552944fb46>:1: RuntimeWarning: invalid value encountered in true_divide
  np.array(0) / np.array(0) #0做了除数?





nan

https://www.cnblogs.com/xieshengsen/p/6822772.html

np.array(0) // np.array(0) #???
<ipython-input-49-ee6ad52ed3b8>:1: RuntimeWarning: divide by zero encountered in floor_divide
  np.array(0) // np.array(0) #???





0
np.divide(np.array(0) ,np.array(0) )
<ipython-input-50-afbe25cd36f2>:1: RuntimeWarning: invalid value encountered in true_divide
  np.divide(np.array(0) ,np.array(0) )





nan

astype 强制数据类型转换
np.nan会显示nan,如果进行计算 结果会显示为NAN

np.array([np.nan]).astype(int).astype(float) #???
array([-2.14748365e+09])
np.array([np.nan])
array([nan])
np.array([np.nan]).astype(int)
array([-2147483648])
29. How to round away from zero a float array ? (★☆☆)

如何从零位对浮点数组做舍入

Z = np.random.uniform(-10,+10,10) #从一个均匀分布[low,high)中随机采样
Z
array([ 3.09435283, -6.18426339, -9.51839763, -3.56467448,  5.59009944,
        4.5967764 , -5.56744765,  1.51740837,  0.0993448 ,  6.8208759 ])

向零舍入的含义是,正数向下舍入,负数向上舍入 ???反着来
ceil 向上取整
[-1.7, -1.5, -0.2, 0.2, 1.5, 1.7, 2.0]
=>[-1., -1., -0., 1., 2., 2., 2.]

print (np.copysign(np.ceil(np.abs(Z)), Z))
[  4.  -7. -10.  -4.   6.   5.  -6.   2.   1.   7.]
np.abs(Z)
array([3.09435283, 6.18426339, 9.51839763, 3.56467448, 5.59009944,
       4.5967764 , 5.56744765, 1.51740837, 0.0993448 , 6.8208759 ])
np.ceil(np.abs(Z))
array([ 4.,  7., 10.,  4.,  6.,  5.,  6.,  2.,  1.,  7.])
answer(29)
# Author: Charles R Harris

Z = np.random.uniform(-10,+10,10)
print(np.copysign(np.ceil(np.abs(Z)), Z))

# More readable but less efficient
print(np.where(Z>0, np.ceil(Z), np.floor(Z)))
30. How to find common values between two arrays? (★☆☆)
z1=np.random.randint(0,10,10)
z1
array([9, 1, 2, 1, 7, 5, 8, 5, 3, 1])
z2=np.random.randint(0,10,10)
np.intersect1d(z1,z2)
array([2, 5, 7, 9])
31. How to ignore all numpy warnings (not recommended)? (★☆☆)
answer(31)
# Suicide mode on
defaults = np.seterr(all="ignore")
Z = np.ones(1) / 0

# Back to sanity
_ = np.seterr(**defaults)

# Equivalently with a context manager
with np.errstate(all="ignore"):
    np.arange(3) / 0
32. Is the following expressions true? (★☆☆)
np.sqrt(-1) == np.emath.sqrt(-1)
np.sqrt(-1)  # 返回NaN
<ipython-input-62-573d56e058a3>:1: RuntimeWarning: invalid value encountered in sqrt
  np.sqrt(-1)





nan
np.emath.sqrt(-1) #对于负输入元素,将返回一个虚数
1j

false

33. How to get the dates of yesterday, today and tomorrow? (★☆☆)

timedelta64的参数是一个表示单位数的数字,以及一个日期/时间单位,例如(D)ay、(M)onth、(Y)ear、(h)ours、(M)inutes或(s)econds。timedelta64数据类型还接受字符串“NAT”来代替“Not a Time”值的数字。

answer(33)
yesterday = np.datetime64('today') - np.timedelta64(1)
today     = np.datetime64('today')
tomorrow  = np.datetime64('today') + np.timedelta64(1)
yesterday = np.datetime64('today') - np.timedelta64(1)
#yesterday = np.datetime64('today', 'D') - np.timedelta64(1, 'D')
yesterday
numpy.datetime64('2021-07-25')
print ("Yesterday is " + str(yesterday))
Yesterday is 2021-07-25
34. How to get all the dates corresponding to the month of July 2016? (★★☆)
#datetime类型与许多常见的numpy函数一起使用。 arange 可用于生成日期范围。
np.arange('2016-07', '2016-08', dtype='datetime64[D]')
array(['2016-07-01', '2016-07-02', '2016-07-03', '2016-07-04',
       '2016-07-05', '2016-07-06', '2016-07-07', '2016-07-08',
       '2016-07-09', '2016-07-10', '2016-07-11', '2016-07-12',
       '2016-07-13', '2016-07-14', '2016-07-15', '2016-07-16',
       '2016-07-17', '2016-07-18', '2016-07-19', '2016-07-20',
       '2016-07-21', '2016-07-22', '2016-07-23', '2016-07-24',
       '2016-07-25', '2016-07-26', '2016-07-27', '2016-07-28',
       '2016-07-29', '2016-07-30', '2016-07-31'], dtype='datetime64[D]')
35. How to compute ((A+B)*(-A/2)) in place (without copy)? (★★☆)

如何直接在位计算(A+B)*(-A/2)(不建立副本)

A = np.ones(3)*1
B = np.ones(3)*2
C = np.ones(3)*3
#out 存储结果的位置
np.add(A,B,out=B)
array([4., 4., 4.])
np.divide(A,2,A)
array([0.5, 0.5, 0.5])
np.negative(A,A)
array([0.5, 0.5, 0.5])
np.multiply(B,A)
array([2., 2., 2.])
36. Extract the integer part of a random array of positive numbers using 4 different methods (★★☆)

用五种不同的方法去提取一个随机数组的整数部分

z=np.random.uniform(0,10,10)
z
array([9.20626007, 4.44207217, 4.55416445, 0.74412368, 3.87870002,
       4.40559099, 5.10080989, 1.36000054, 5.43351579, 4.57208323])
z%1
array([0.20626007, 0.44207217, 0.55416445, 0.74412368, 0.87870002,
       0.40559099, 0.10080989, 0.36000054, 0.43351579, 0.57208323])
z-z%1
array([9., 4., 4., 0., 3., 4., 5., 1., 5., 4.])
np.floor(z) #向下取整
array([9., 4., 4., 0., 3., 4., 5., 1., 5., 4.])
np.ceil(z)-1 #向上取整
array([9., 4., 4., 0., 3., 4., 5., 1., 5., 4.])
z.astype(int)
array([9, 4, 4, 0, 3, 4, 5, 1, 5, 4])
np.trunc(z)
array([9., 4., 4., 0., 3., 4., 5., 1., 5., 4.])

numpy.trunc 按元素返回输入的截断值。
标量的截断值 x 是最近的整数 i 接近于零比 x 是。简而言之,有符号数的小数部分 x 被丢弃。

37. Create a 5x5 matrix with row values ranging from 0 to 4 (★★☆)
z=np.zeros((5,5))
z+=np.arange(5)
z
array([[0., 1., 2., 3., 4.],
       [0., 1., 2., 3., 4.],
       [0., 1., 2., 3., 4.],
       [0., 1., 2., 3., 4.],
       [0., 1., 2., 3., 4.]])
38. Consider a generator function that generates 10 integers and use it to build an array (★☆☆)
def generatorfunc():
    for i in range(10):
        yield i

x=np.fromiter(generatorfunc(),float)
x
array([0., 1., 2., 3., 4., 5., 6., 7., 8., 9.])

带有 yield 的函数在 Python 中被称之为 generator(生成器)
https://www.runoob.com/w3cnote/python-yield-used-analysis.html

numpy.fromiter从可Iterable对象创建新的一维数组。
numpy.fromiter(iter, dtype, count=- 1, *, like=None)
count要读取的项目数 可迭代的 . 默认值为-1,表示读取所有数据。

iterable = (x*x for x in range(5))
np.fromiter(iterable, float)
array([ 0., 1., 4., 9., 16.])

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

创建一个长度为10的随机向量,其值域范围从0到1,但是不包括0和1

np.linspace(0,1,11,False)[1:] #从第一位取所有
array([0.09090909, 0.18181818, 0.27272727, 0.36363636, 0.45454545,
       0.54545455, 0.63636364, 0.72727273, 0.81818182, 0.90909091])
40. Create a random vector of size 10 and sort it (★★☆)
x=np.random.random(10)
np.sort(x)
array([0.17597158, 0.23604689, 0.23843589, 0.35093462, 0.36429939,
       0.39456373, 0.43786685, 0.44408553, 0.61492424, 0.84600839])
41. How to sum a small array faster than np.sum? (★★☆)
z=np.arange(10)
np.add.reduce(z)
45

reduce() 函数会对参数序列中元素进行累积。
add.reduce()等价于sum()。

42. Consider two random array A and B, check if they are equal (★★☆)
A=np.random.randint(0,2,5)
A
array([0, 0, 0, 0, 0])
B=np.random.randint(0,2,5)
B
array([1, 1, 0, 0, 0])
#假设阵列的形状相同,并且允许值的比较
np.allclose(A,B)
False
#检查形状和元素值,无公差(值必须完全相等)
np.array_equal(A,B)
False
np.array_equiv(A,B)
False
allclose
如果两个数组在一个公差内按元素方向相等,则返回true。tol=1e-05, atol=1e-08,rtol浮动,相对公差参数(见注释)。atol浮动,绝对公差参数(见注释)。

array_equiv
如果输入数组的形状一致且所有元素都相等,则返回true。

array_equal
如果两个数组的形状和元素相同,则为true,否则为false。
43. Make an array immutable不变的 (read-only) (★★☆)

创建一个只读数组(read-only)

answer(43)
Z = np.zeros(10)
Z.flags.writeable = False
Z[0] = 1
Z = np.zeros(10)
Z.flags.writeable = False
Z[0] = 1
---------------------------------------------------------------------------

ValueError                                Traceback (most recent call last)

<ipython-input-12-dcc5e7f145b5> in <module>
      1 Z = np.zeros(10)
      2 Z.flags.writeable = False
----> 3 Z[0] = 1


ValueError: assignment destination is read-only
44. Consider a random 10x2 matrix representing cartesian coordinates, convert them to polar coordinates (★★☆)

将笛卡尔坐标下的一个10x2的矩阵转换为极坐标形式

Z = np.random.random((10,2))
Z
array([[0.64675231, 0.96848351],
       [0.20433521, 0.16676645],
       [0.68945731, 0.19988734],
       [0.51551036, 0.44503793],
       [0.59599894, 0.02943923],
       [0.27738068, 0.08507193],
       [0.22212389, 0.64175478],
       [0.82844093, 0.31156256],
       [0.02566146, 0.0306882 ],
       [0.23890295, 0.8730525 ]])
answer(44)
Z = np.random.random((10,2))
X,Y = Z[:,0], Z[:,1]
R = np.sqrt(X**2+Y**2)
T = np.arctan2(Y,X)
print(R)
print(T)
X,Y = Z[:,0], Z[:,1] #矩阵第一列作为x轴,第二列作为y轴
X
array([0.64675231, 0.20433521, 0.68945731, 0.51551036, 0.59599894,
       0.27738068, 0.22212389, 0.82844093, 0.02566146, 0.23890295])
Y
array([0.96848351, 0.16676645, 0.19988734, 0.44503793, 0.02943923,
       0.08507193, 0.64175478, 0.31156256, 0.0306882 , 0.8730525 ])
R = np.sqrt(X**2+Y**2)
T = np.arctan2(Y,X) #角度,tanɵ=y/x
45. Create random vector of size 10 and replace the maximum value by 0 (★★☆)
x=np.random.randint(1,11,10)
x
array([ 8,  4,  3, 10, 10,  9,  6,  5, 10,  6])
#如果最大值出现多次,则返回与第一次出现对应的索引。
x[np.argmax(x)]=0 
x
array([ 8,  4,  3,  0, 10,  9,  6,  5, 10,  6])
x[x.argmax()]=0
x
array([ 8,  4,  3,  0,  0,  9,  6,  5, 10,  6])
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] 区域

import matplotlib.pyplot as plt

https://blog.csdn.net/lllxxq141592654/article/details/81532855
把两个数组的笛卡尔积内的元素的第一二个坐标分别放入两个矩阵中。

x = np.array([0, 1])
y = np.array([0, 1])
X, Y = np.meshgrid(x, y)
print(X)
print(Y)


plt.plot(X, Y,
         color='red',  # 全部点设置为红色
         marker='.',  # 点的形状为圆点
         linestyle='')  # 线型为空,也即点与点之间不用线连接
plt.grid(True)
plt.show()

[[0 1]
 [0 1]]
[[0 0]
 [1 1]]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-gK8YWD50-1627545039407)(output_172_1.png)]

answer(46)
Z = np.zeros((5,5), [('x',float),('y',float)])
Z['x'], Z['y'] = np.meshgrid(np.linspace(0,1,5),
                             np.linspace(0,1,5))
print(Z)
Z = np.zeros((5,5), [('x',float),('y',float)])
#第二个参数是自定义dtype
Z
array([[(0., 0.), (0., 0.), (0., 0.), (0., 0.), (0., 0.)],
       [(0., 0.), (0., 0.), (0., 0.), (0., 0.), (0., 0.)],
       [(0., 0.), (0., 0.), (0., 0.), (0., 0.), (0., 0.)],
       [(0., 0.), (0., 0.), (0., 0.), (0., 0.), (0., 0.)],
       [(0., 0.), (0., 0.), (0., 0.), (0., 0.), (0., 0.)]],
      dtype=[('x', '<f8'), ('y', '<f8')])
Z['x'], Z['y'] = np.meshgrid(np.linspace(0,1,5),
                             np.linspace(0,1,5))
print(Z)
[[(0.  , 0.  ) (0.25, 0.  ) (0.5 , 0.  ) (0.75, 0.  ) (1.  , 0.  )]
 [(0.  , 0.25) (0.25, 0.25) (0.5 , 0.25) (0.75, 0.25) (1.  , 0.25)]
 [(0.  , 0.5 ) (0.25, 0.5 ) (0.5 , 0.5 ) (0.75, 0.5 ) (1.  , 0.5 )]
 [(0.  , 0.75) (0.25, 0.75) (0.5 , 0.75) (0.75, 0.75) (1.  , 0.75)]
 [(0.  , 1.  ) (0.25, 1.  ) (0.5 , 1.  ) (0.75, 1.  ) (1.  , 1.  )]]
plt.plot(Z['x'], Z['y'],
         color='red',  # 全部点设置为红色
         marker='.',  # 点的形状为圆点
         linestyle='')  # 线型为空,也即点与点之间不用线连接
plt.grid(True)
plt.show()

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-fQSfTwwE-1627545039408)(output_176_0.png)]

47. Given two arrays, X and Y, construct the Cauchy matrix C (Cij =1/(xi - yj))
X = np.arange(8)
Y = X + 0.5
X
array([0, 1, 2, 3, 4, 5, 6, 7])
X.ndim
1
X.shape
(8,)
Y
array([0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5])
np.subtract.outer(X, Y) #8*8
array([[-0.5, -1.5, -2.5, -3.5, -4.5, -5.5, -6.5, -7.5],
       [ 0.5, -0.5, -1.5, -2.5, -3.5, -4.5, -5.5, -6.5],
       [ 1.5,  0.5, -0.5, -1.5, -2.5, -3.5, -4.5, -5.5],
       [ 2.5,  1.5,  0.5, -0.5, -1.5, -2.5, -3.5, -4.5],
       [ 3.5,  2.5,  1.5,  0.5, -0.5, -1.5, -2.5, -3.5],
       [ 4.5,  3.5,  2.5,  1.5,  0.5, -0.5, -1.5, -2.5],
       [ 5.5,  4.5,  3.5,  2.5,  1.5,  0.5, -0.5, -1.5],
       [ 6.5,  5.5,  4.5,  3.5,  2.5,  1.5,  0.5, -0.5]])
C = 1.0 / np.subtract.outer(X, Y)
C
array([[-2.        , -0.66666667, -0.4       , -0.28571429, -0.22222222,
        -0.18181818, -0.15384615, -0.13333333],
       [ 2.        , -2.        , -0.66666667, -0.4       , -0.28571429,
        -0.22222222, -0.18181818, -0.15384615],
       [ 0.66666667,  2.        , -2.        , -0.66666667, -0.4       ,
        -0.28571429, -0.22222222, -0.18181818],
       [ 0.4       ,  0.66666667,  2.        , -2.        , -0.66666667,
        -0.4       , -0.28571429, -0.22222222],
       [ 0.28571429,  0.4       ,  0.66666667,  2.        , -2.        ,
        -0.66666667, -0.4       , -0.28571429],
       [ 0.22222222,  0.28571429,  0.4       ,  0.66666667,  2.        ,
        -2.        , -0.66666667, -0.4       ],
       [ 0.18181818,  0.22222222,  0.28571429,  0.4       ,  0.66666667,
         2.        , -2.        , -0.66666667],
       [ 0.15384615,  0.18181818,  0.22222222,  0.28571429,  0.4       ,
         0.66666667,  2.        , -2.        ]])
print(np.linalg.det(C)) # 计算数组的行列式。
3638.1636371179666

https://blog.csdn.net/weixin_43584807/article/details/103093386

48. Print the minimum and maximum representable value for each numpy scalar type (★★☆)

打印每个numpy标量类型的最小值和最大值?

for dtype in [np.int8, np.int32, np.int64]: #整数类型的机器限制
    print(np.iinfo(dtype).min)
    print(np.iinfo(dtype).max)
-128
127
-2147483648
2147483647
-9223372036854775808
9223372036854775807
for dtype in [np.float32, np.float64]: #浮点类型的机器限制
    print(np.finfo(dtype).min)
    print(np.finfo(dtype).max)
    print(np.finfo(dtype).eps)
-3.4028235e+38
3.4028235e+38
1.1920929e-07
-1.7976931348623157e+308
1.7976931348623157e+308
2.220446049250313e-16

eps浮动
1.0与大于1.0的次最小可表示浮点数之间的差值。例如,对于IEEE-754标准中的64位二进制浮点, eps = 2**-52 ,约2.22e-16。

49. How to print all the values of an array? (★★☆)

如何打印一个数组中的所有数值?

np.set_printoptions(threshold=None)
Z = np.zeros((100,100))
print (Z)
[[0. 0. 0. ... 0. 0. 0.]
 [0. 0. 0. ... 0. 0. 0.]
 [0. 0. 0. ... 0. 0. 0.]
 ...
 [0. 0. 0. ... 0. 0. 0.]
 [0. 0. 0. ... 0. 0. 0.]
 [0. 0. 0. ... 0. 0. 0.]]
np.set_printoptions(threshold=np.nan)
Z = np.zeros((16,16))
print (Z)
---------------------------------------------------------------------------

ValueError                                Traceback (most recent call last)

<ipython-input-50-e898f207b2c6> in <module>
----> 1 np.set_printoptions(threshold=np.nan)
      2 Z = np.zeros((16,16))
      3 print (Z)


D:\Anaconda\lib\site-packages\numpy\core\arrayprint.py in set_printoptions(precision, threshold, edgeitems, linewidth, suppress, nanstr, infstr, formatter, sign, floatmode, legacy)
    241 
    242     """
--> 243     opt = _make_options_dict(precision, threshold, edgeitems, linewidth,
    244                              suppress, nanstr, infstr, sign, formatter,
    245                              floatmode, legacy)


D:\Anaconda\lib\site-packages\numpy\core\arrayprint.py in _make_options_dict(precision, threshold, edgeitems, linewidth, suppress, nanstr, infstr, sign, formatter, floatmode, legacy)
     84             raise TypeError("threshold must be numeric")
     85         if np.isnan(threshold):
---> 86             raise ValueError("threshold must be non-NAN, try "
     87                              "sys.maxsize for untruncated representation")
     88     return options


ValueError: threshold must be non-NAN, try sys.maxsize for untruncated representation
np.set_printoptions(threshold=2**63 - 1)
Z = np.zeros((100,100))
print (Z)
[[0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
  0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0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0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
  0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
  0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
  0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
  0. 0. 0. 0.]
 [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
  0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
  0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
  0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
  0. 0. 0. 0.]
 [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
  0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
  0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
  0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
  0. 0. 0. 0.]]
50. How to find the closest value (to a given scalar) in a vector? (★★☆)

给定标量时,如何找到数组中最接近标量的值?

Z = np.arange(100)
Z
array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,
       17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
       34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
       51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67,
       68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
       85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99])
v = np.random.uniform(0,100)
v
66.21693746924979
index = (np.abs(Z-v)).argmin()
Z[index]
66
51. Create a structured array representing a position (x,y) and a color (r,g,b) (★★☆)

创建一个表示位置(x,y)和颜色(r,g,b)的结构化数组

https://blog.csdn.net/qq_27825451/article/details/82425512
又碰到了结构化数组和dtype,之前一直似懂非懂,这次特地搜了下,算是豁然开朗了很多。

X=np.zeros(10,[('position',[('x',float),
                             ('y',float)]),
                ('color',[('r',float),
                          ('g',float),
                          ('b',float)])])
X
array([((0., 0.), (0., 0., 0.)), ((0., 0.), (0., 0., 0.)),
       ((0., 0.), (0., 0., 0.)), ((0., 0.), (0., 0., 0.)),
       ((0., 0.), (0., 0., 0.)), ((0., 0.), (0., 0., 0.)),
       ((0., 0.), (0., 0., 0.)), ((0., 0.), (0., 0., 0.)),
       ((0., 0.), (0., 0., 0.)), ((0., 0.), (0., 0., 0.))],
      dtype=[('position', [('x', '<f8'), ('y', '<f8')]), ('color', [('r', '<f8'), ('g', '<f8'), ('b', '<f8')])])

总结来说,用其他语言解释就是不断嵌套,定义了一个类,包括多个属性,属性也可以是一个类,属性包括属性名,类型,长度,类用[],属性用()------瞎解释,自己差不多懂了,写的时候要换行写,容易辨别,写在一行容易错

52. Consider a random vector with shape (100,2) representing coordinates, find point by point distances (★★☆)

对一个表示坐标形状为(100,2)的随机向量,找到点与点的距离

np.set_printoptions(threshold=None)
z=np.random.random((100,2))

53. How to convert a float (32 bits) array into an integer (32 bits) in place?

如何将32位的浮点数(float)转换为对应的整数(integer)

answer(53)
# Thanks Vikas (https://stackoverflow.com/a/10622758/5989906)
# & unutbu (https://stackoverflow.com/a/4396247/5989906)
Z = (np.random.rand(10)*100).astype(np.float32)
Y = Z.view(np.int32)
Y[:] = Z
print(Y)
x=(np.random.rand(10)*100).astype(np.float32) #astype不改变原数组,不能分开算
x
array([71.35187 , 73.083694, 64.51008 , 20.417986, 88.11627 , 47.83035 ,
       33.055374, 35.958733, 84.74487 , 17.220655], dtype=float32)
z=x.view(np.int32)
z
array([1116648488, 1116875482, 1115751721, 1101223945, 1118845832,
       1111446087, 1107572916, 1108334014, 1118403936, 1099547623])
z[:]=x
z
array([71, 73, 64, 20, 88, 47, 33, 35, 84, 17])
x
array([9.95e-44, 1.02e-43, 8.97e-44, 2.80e-44, 1.23e-43, 6.59e-44,
       4.62e-44, 4.90e-44, 1.18e-43, 2.38e-44], dtype=float32)

放弃,完全看不懂,怎么全是x给z赋值,而且数字这么诡异,人傻了。。。。。

54. How to read the following file? (★★☆)
1, 2, 3, 4, 5
6,  ,  , 7, 8
 ,  , 9,10,11
answer(54)
from io import StringIO

# Fake file
s = StringIO('''1, 2, 3, 4, 5

                6,  ,  , 7, 8

                 ,  , 9,10,11
''')
Z = np.genfromtxt(s, delimiter=",", dtype=np.int)
print(Z)

delimiterstr、int或sequence,可选
用于分隔值的字符串。默认情况下,任何连续的空格都充当分隔符。整数或整数序列也可以作为每个字段的宽度提供。
根据输出情况缺失值自动填充-1,但是没看到文档里有写;如果本来就有-1值咋整???太复杂了哎

from io import StringIO
s = StringIO('''1, 2, 3, 4, 5

                6,  ,  , 7, 8

                 ,  , 9,10,11
''')
Z = np.genfromtxt(s, delimiter=",", dtype=int)
print(Z)
[[ 1  2  3  4  5]
 [ 6 -1 -1  7  8]
 [-1 -1  9 10 11]]
55. What is the equivalent of enumerate枚举 for numpy arrays? (★★☆)

对于numpy数组,enumerate的等价操作是什么

三维

Z = np.arange(9).reshape(3,3)
for index, value in np.ndenumerate(Z):
    print (index, value)
(0, 0) 0
(0, 1) 1
(0, 2) 2
(1, 0) 3
(1, 1) 4
(1, 2) 5
(2, 0) 6
(2, 1) 7
(2, 2) 8
Z
array([[0, 1, 2],
       [3, 4, 5],
       [6, 7, 8]])

一维

arr = np.array([1, 2, 3])

for idx, x in np.ndenumerate(arr):
  print(idx, x)
(0,) 1
(1,) 2
(2,) 3

二维

arr = np.array([[1, 2, 3, 4], [5, 6, 7, 8]])

for idx, x in np.ndenumerate(arr):
  print(idx, x)
(0, 0) 1
(0, 1) 2
(0, 2) 3
(0, 3) 4
(1, 0) 5
(1, 1) 6
(1, 2) 7
(1, 3) 8
for index in np.ndindex(Z.shape):
    print (index, Z[index])
(0, 0) 0
(0, 1) 1
(0, 2) 2
(1, 0) 3
(1, 1) 4
(1, 2) 5
(2, 0) 6
(2, 1) 7
(2, 2) 8
Z.shape
(3, 3)
56. Generate a generic 2D Gaussian-like array (★★☆)

生成一个通用的二维Gaussian-like数组(标准正太分布,miu=0.sigma=1)

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-LrKo8QIQ-1627545039410)(attachment:image.png)]

answer(56)
X, Y = np.meshgrid(np.linspace(-1,1,10), np.linspace(-1,1,10))
D = np.sqrt(X*X+Y*Y)
sigma, mu = 1.0, 0.0
G = np.exp(-( (D-mu)**2 / ( 2.0 * sigma**2 ) ) )
print(G)
X, Y = np.meshgrid(np.linspace(-1,1,10), np.linspace(-1,1,10))
D = np.sqrt(X*X+Y*Y)
sigma, mu = 1.0, 0.0
G = np.exp(-( (D-mu)**2 / ( 2.0 * sigma**2 ) ) )
print(G)
[[0.36787944 0.44822088 0.51979489 0.57375342 0.60279818 0.60279818
  0.57375342 0.51979489 0.44822088 0.36787944]
 [0.44822088 0.54610814 0.63331324 0.69905581 0.73444367 0.73444367
  0.69905581 0.63331324 0.54610814 0.44822088]
 [0.51979489 0.63331324 0.73444367 0.81068432 0.85172308 0.85172308
  0.81068432 0.73444367 0.63331324 0.51979489]
 [0.57375342 0.69905581 0.81068432 0.89483932 0.9401382  0.9401382
  0.89483932 0.81068432 0.69905581 0.57375342]
 [0.60279818 0.73444367 0.85172308 0.9401382  0.98773022 0.98773022
  0.9401382  0.85172308 0.73444367 0.60279818]
 [0.60279818 0.73444367 0.85172308 0.9401382  0.98773022 0.98773022
  0.9401382  0.85172308 0.73444367 0.60279818]
 [0.57375342 0.69905581 0.81068432 0.89483932 0.9401382  0.9401382
  0.89483932 0.81068432 0.69905581 0.57375342]
 [0.51979489 0.63331324 0.73444367 0.81068432 0.85172308 0.85172308
  0.81068432 0.73444367 0.63331324 0.51979489]
 [0.44822088 0.54610814 0.63331324 0.69905581 0.73444367 0.73444367
  0.69905581 0.63331324 0.54610814 0.44822088]
 [0.36787944 0.44822088 0.51979489 0.57375342 0.60279818 0.60279818
  0.57375342 0.51979489 0.44822088 0.36787944]]
???不懂题目
57. How to randomly place p elements in a 2D array? (★★☆)

对一个二维数组,如何在其内部随机放置p个元素?

n = 10
p = 3
Z = np.zeros((n,n))
#放1
# np.random.choice(range(n*n), p, replace=False) #array([68, 83, 18])(0,100)的范围内生成均匀随机样本3个
np.put(Z, np.random.choice(range(n*n), p, replace=False),1)
print (Z)
array([68, 83, 18])
range(10*10)
range(0, 100)

numpy.put替换
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-AxY9Twhb-1627545039412)(attachment:image.png)]
#“clip”模式意味着所有太大的索引都将替换为沿该轴寻址最后一个元素的索引。

numpy.random.choice从给定的一维数组生成随机样本
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-cLPy8G67-1627545039413)(attachment:image-2.png)]
p类似一维数组,可选
与a中每个条目相关的概率。如果没有给定,则样本假定a中所有条目的分布均匀。
使用此函数无法从二维数组中随机抽取行,但可以使用 Generator.choice 通过它 axis 关键字。

58. Subtract the mean of each row of a matrix (★★☆)

减去一个矩阵中的每一行的平均值

x=np.random.rand(5,10) #生成
x
array([[0.07754983, 0.28825807, 0.43613348, 0.87533956, 0.30084899,
        0.28228275, 0.59903432, 0.86360564, 0.27381128, 0.0283315 ],
       [0.75767303, 0.82801817, 0.72202028, 0.67219926, 0.93863966,
        0.55567946, 0.58286021, 0.8792868 , 0.74897285, 0.16183515],
       [0.8389071 , 0.13933747, 0.47932373, 0.25415078, 0.7040179 ,
        0.34858892, 0.48558245, 0.85124684, 0.44410478, 0.76117947],
       [0.74141128, 0.68739785, 0.40331523, 0.86861186, 0.40317327,
        0.88794071, 0.13428306, 0.00330895, 0.52673849, 0.53132285],
       [0.70543378, 0.04123617, 0.7125698 , 0.06484623, 0.54493191,
        0.89130818, 0.14560607, 0.5114785 , 0.96471874, 0.1031025 ]])
广播机制

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-xba69cWd-1627545039414)(attachment:image.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-tQV1vNEi-1627545039415)(attachment:image-2.png)]

y=x-np.mean(x,axis=1)
y
---------------------------------------------------------------------------

ValueError                                Traceback (most recent call last)

<ipython-input-96-f27a6a920f3a> in <module>
----> 1 y=x-np.mean(x,axis=1)
      2 y


ValueError: operands could not be broadcast together with shapes (5,10) (5,) 

keepdims可选的布尔
如果设置为“真”,则缩小的轴将保留在结果中,作为尺寸为1的尺寸。使用此选项,结果将针对输入数组正确广播。

如果传递了默认值,则 keepdims 不会传给 mean 子类方法 ndarray 但是,任何非默认值都是。如果子类的方法不实现 keepdims 将引发任何异常。

np.mean(x,axis=1)
array([0.31325645, 0.50138901, 0.64214817, 0.54361337, 0.55210806])
np.mean(x,axis=1,keepdims=True)
array([[0.31325645],
       [0.50138901],
       [0.64214817],
       [0.54361337],
       [0.55210806]])
X = np.random.rand(5, 10)
# Recent versions of numpy
Y = X - X.mean(axis=1, keepdims=True)
print(Y)
[[-0.36205416  0.5414192  -0.22909991 -0.18913801 -0.12371012  0.23256322
  -0.19724753  0.60432461 -0.12670296 -0.15035436]
 [-0.04676544  0.06439615  0.0056881  -0.06131033  0.46152732 -0.37904278
  -0.40683083  0.00482544  0.28075537  0.07675701]
 [ 0.2374288   0.40910667 -0.22915521  0.07463345 -0.27153334 -0.00952941
  -0.24817052  0.2531104   0.03925578 -0.25514662]
 [-0.31980829  0.12841661  0.12055613 -0.20994652  0.00394996  0.4374066
   0.12802987 -0.36538342 -0.17462784  0.2514069 ]
 [ 0.31963148  0.16435793 -0.25528746  0.41276113  0.24437394  0.01337083
   0.10645655 -0.26216032 -0.42957407 -0.31393002]]
X.mean(axis=1)
array([0.39355011, 0.51055273, 0.3582653 , 0.50357204, 0.54478071])
X.mean(axis=1).reshape(-1, 1)
array([[0.39355011],
       [0.51055273],
       [0.3582653 ],
       [0.50357204],
       [0.54478071]])
59. How to sort an array by the nth column? (★★☆)

如何通过第n列对一个数组进行排序

x=np.random.randint(0,10,(2,3))
x
array([[9, 4, 4],
       [5, 0, 7]])
print (x[x[:,1].argsort()])
[[5 0 7]
 [9 4 4]]
x[:,1] #第二列
array([4, 0])
x[:,1].argsort() #返回大小的索引,0小1大
array([1, 0], dtype=int64)
60. How to tell if a given 2D array has null columns? (★★☆)

如何检查一个二维数组是否有空列?

1.numpy.array.any()和numpy.array.all(),一个是或操作一个是与操作

np.array.any()是或操作,任意一个元素为True,输出为True。

np.array.all()是与操作,所有元素为True,输出为True。

x=np.random.randint(0,3,(3,10))
x
array([[0, 0, 2, 1, 1, 1, 1, 0, 1, 1],
       [0, 1, 2, 1, 1, 0, 1, 1, 2, 0],
       [0, 1, 0, 0, 2, 2, 2, 0, 1, 2]])
~np.any(x,axis=0) #只判断列
array([ True, False, False, False, False, False, False, False, False,
       False])
print ((~Z.any(axis=0)).any()) #不加axis是所有加一起判断
True
61. Find the nearest value from a given value in an array (★★☆)

从数组中的给定值中找出最近的值

x=np.random.uniform(0,1,10)
z=0.5
x
array([0.15525201, 0.52760422, 0.89255232, 0.22634058, 0.49320877,
       0.76687643, 0.27592277, 0.3958963 , 0.85868191, 0.574109  ])
m=x[np.argmin((np.abs(x-0.5)))]
m
0.49320877255000206
l = x.flat[np.abs(x- z).argmin()]
l
0.49320877255000206
x=np.random.uniform(0,1,(2,5))
z=0.5
x
array([[0.84835409, 0.75729473, 0.87409659, 0.99975984, 0.65690204],
       [0.68944573, 0.39756477, 0.55407272, 0.1019063 , 0.34701769]])
m=x[np.argmin((np.abs(x-0.5)))] #多维数组不能直接用索引找,得用flat压缩为一维矩阵再进行索引
m
---------------------------------------------------------------------------

IndexError                                Traceback (most recent call last)

<ipython-input-14-bf9246f8de3e> in <module>
----> 1 m=x[np.argmin((np.abs(x-0.5)))]
      2 m


IndexError: index 7 is out of bounds for axis 0 with size 2
l = x.flat[np.abs(x- z).argmin()]
l
0.5540727158063303
62. Considering two arrays with shape (1,3) and (3,1), how to compute their sum using an iterator? (★★☆)

如何用迭代器(iterator)计算两个分别具有形状(1,3)和(3,1)的数组? (求和)

a=np.arange(3).reshape(1,3)
a
array([[0, 1, 2]])
b=np.arange(3).reshape(3,1)
b
array([[0],
       [1],
       [2]])
it=np.nditer([a,b])
for x,y in it:
    print(x,y)
0 0
1 0
2 0
0 1
1 1
2 1
0 2
1 2
2 2
it = np.nditer([a,b,None])
for x,y,z in it: 
    z[...] = x + y
print (it.operands[2])
[[0 1 2]
 [1 2 3]
 [2 3 4]]
print(z)
4
answer(62)
A = np.arange(3).reshape(3,1)
B = np.arange(3).reshape(1,3)
it = np.nditer([A,B,None])
for x,y,z in it: z[...] = x + y
print(it.operands[2])

???

https://blog.csdn.net/jiangjiang_jian/article/details/77540599

63. Create an array class that has a name attribute (★★☆)

创建一个具有name属性的数组类


64. Consider a given vector, how to add 1 to each element indexed by a second vector (be careful with repeated indices)? (★★★)

考虑一个给定的向量,如何对由第二个向量索引的每个元素加1(小心重复的索引)?
意思是?第二个向量I是索引,索引到的Z中的数+1,如果有多次索引,索引几次加几次???

Z = np.ones(10)
I = np.random.randint(0,len(Z),20)
print(Z)
print(I)
[1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
[4 1 2 7 1 8 5 6 9 5 4 4 2 1 0 0 0 5 7 5]
np.bincount(I) #计数非负整数数组中每个值的出现次数。
array([3, 3, 2, 0, 3, 4, 1, 2, 1, 1], dtype=int64)
np.bincount(I, minlength=len(Z)) #没懂minlength作用???
array([3, 3, 2, 0, 3, 4, 1, 2, 1, 1], dtype=int64)
Z += np.bincount(I, minlength=len(Z))
Z
array([4., 4., 3., 1., 4., 5., 2., 3., 2., 2.])
Z = np.ones(10)
I = np.random.randint(0,len(Z),20)
print(Z)
print(I)
[1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
[1 4 7 6 3 8 8 7 0 8 9 4 7 1 0 2 1 7 4 7]
np.add.at(Z,I,1)
Z
array([3., 4., 2., 2., 4., 1., 2., 6., 4., 2.])

ufunc.at(a, indices, b=None, /)
为“indexs”指定的元素对操作数“a”执行未缓冲的就地操作。对于添加ufunc,此方法等效于 a[indices] += b ,但对索引多次的元素累积结果除外。例如, a[[0,0]] += 1 由于缓冲,将只增加第一个元素一次,而 add.at(a, [0,0], 1) 将第一个元素递增两次。
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-FhkwEhri-1627545039416)(attachment:image.png)]

65. How to accumulate elements of a vector (X) to an array (F) based on an index list (I)? (★★★)

根据索引列表(I),如何将向量(X)的元素累加到数组(F)

X = [1,2,3,4,5,6] #X是目标
I = [1,3,9,3,4,1] #I是索引,从0开始,由小到大 X对应的数字相加
#从0开始,0没有索引为0,1有两个1+6=7,2无为0,3有两个2+4=6
F=np.bincount(I,X)
F
array([0., 7., 0., 6., 5., 0., 0., 0., 0., 3.])

如果 weights 指定输入数组的权重,即如果一个值 n 在位置处找到 i , out[n] += weight[i] 而不是 out[n] += 1 .

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-pLyaR25J-1627545039417)(attachment:image.png)]

66. Considering a (w,h,3) image of (dtype=ubyte), compute the number of unique colors (★★☆)

考虑一个(dtype=ubyte) 的 (w,h,3)图像,计算其唯一颜色的数量(★★★)

w,h = 16,16
I = np.random.randint(0,2,(h,w,3)).astype(np.ubyte) #0,1数组成,16*16*3

…代替了切片操作中前面所有的:, 即a[:, :, None] 和a[…, None]等价

67. Considering a four dimensions array, how to get sum over the last two axis at once? (★★★)

考虑一个四维数组,如何一次性计算出最后两个轴(axis)的和

A = np.random.randint(0,10,(3,4,3,4))
s=A.sum(axis=(-2,-1))
s #?????
array([[44, 42, 35, 53],
       [66, 60, 44, 56],
       [38, 44, 45, 45]])

axis无、int或int的元组,可选
执行求和的轴。默认值axis=none将对输入数组的所有元素求和。如果轴为负,则从最后一个轴到第一个轴计数。

68. Considering a one-dimensional vector D, how to compute means of subsets of D using a vector S of same size describing subset indices? (★★★)

考虑一个一维向量D,如何使用相同大小的向量S来计算D子集的均值?


69. How to get the diagonal of a dot product? (★★★)

70. Consider the vector [1, 2, 3, 4, 5], how to build a new vector with 3 consecutive zeros interleaved between each value? (★★★)

71. Consider an array of dimension (5,5,3), how to mulitply it by an array with dimensions (5,5)? (★★★)

72. How to swap two rows of an array? (★★★)

73. Consider a set of 10 triplets describing 10 triangles (with shared vertices), find the set of unique line segments composing all the triangles (★★★)

74. Given a sorted array C that corresponds to a bincount, how to produce an array A such that np.bincount(A) == C? (★★★)

75. How to compute averages using a sliding window over an array? (★★★)

76. Consider a one-dimensional array Z, build a two-dimensional array whose first row is (Z[0],Z[1],Z[2]) and each subsequent row is shifted by 1 (last row should be (Z[-3],Z[-2],Z[-1]) (★★★)

77. How to negate a boolean, or to change the sign of a float inplace? (★★★)

78. Consider 2 sets of points P0,P1 describing lines (2d) and a point p, how to compute distance from p to each line i (P0[i],P1[i])? (★★★)

79. Consider 2 sets of points P0,P1 describing lines (2d) and a set of points P, how to compute distance from each point j (P[j]) to each line i (P0[i],P1[i])? (★★★)

80. Consider an arbitrary array, write a function that extract a subpart with a fixed shape and centered on a given element (pad with a fill value when necessary) (★★★)

81. Consider an array Z = [1,2,3,4,5,6,7,8,9,10,11,12,13,14], how to generate an array R = [[1,2,3,4], [2,3,4,5], [3,4,5,6], …, [11,12,13,14]]? (★★★)

82. Compute a matrix rank (★★★)

83. How to find the most frequent value in an array?

84. Extract all the contiguous 3x3 blocks from a random 10x10 matrix (★★★)

85. Create a 2D array subclass such that Z[i,j] == Z[j,i] (★★★)

86. Consider a set of p matrices wich shape (n,n) and a set of p vectors with shape (n,1). How to compute the sum of of the p matrix products at once? (result has shape (n,1)) (★★★)

87. Consider a 16x16 array, how to get the block-sum (block size is 4x4)? (★★★)

88. How to implement the Game of Life using numpy arrays? (★★★)

89. How to get the n largest values of an array (★★★)

90. Given an arbitrary number of vectors, build the cartesian product (every combinations of every item) (★★★)

91. How to create a record array from a regular array? (★★★)

92. Consider a large vector Z, compute Z to the power of 3 using 3 different methods (★★★)

93. Consider two arrays A and B of shape (8,3) and (2,2). How to find rows of A that contain elements of each row of B regardless of the order of the elements in B? (★★★)

94. Considering a 10x3 matrix, extract rows with unequal values (e.g. [2,2,3]) (★★★)

95. Convert a vector of ints into a matrix binary representation (★★★)

96. Given a two dimensional array, how to extract unique rows? (★★★)

97. Considering 2 vectors A & B, write the einsum equivalent of inner, outer, sum, and mul function (★★★)

98. Considering a path described by two vectors (X,Y), how to sample it using equidistant samples (★★★)?

99. Given an integer n and a 2D array X, select from X the rows which can be interpreted as draws from a multinomial distribution with n degrees, i.e., the rows which only contain integers and which sum to n. (★★★)

100. Compute bootstrapped 95% confidence intervals for the mean of a 1D array X (i.e., resample the elements of an array with replacement N times, compute the mean of each sample, and then compute percentiles over the means). (★★★)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值