How to sum a small array faster than np.sum?
1 | # Author: Evgeni Burovski |
Consider two random array A and B, check if they are equal
1 | A = np.random.randint(0,2,5) |
Make an array immutable (read-only)
1 | Z = np.zeros(10) |
Consider a random 10x2 matrix representing cartesian coordinates, convert them to polar coordinates
1 | Z = np.random.random((10,2)) |
Create random vector of size 10 and replace the maximum value by 0
1 | Z = np.random.random(10) |
Create a structured array with x
and y
coordinates covering the [0,1]x[0,1] area
1 | Z = np.zeros((5,5), [('x',float),('y',float)]) |
Given two arrays, X and Y, construct the Cauchy matrix C (Cij =1/(xi - yj))
1 | # Author: Evgeni Burovski |
Print the minimum and maximum representable value for each numpy scalar type
1 | for dtype in [np.int8, np.int32, np.int64]: |
How to print all the values of an array?
1 | np.set_printoptions(threshold=np.nan) |
How to find the closest value (to a given scalar) in a vector?
1 | Z = np.arange(100) |