Create an array from 0 to 10 using numpy.
import numpy as np
arr = np.arange(11)
arr
Execution result.
array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10])
You can calculate the square root of each number by using the sqrt method.
np.sqrt(arr)
Execution result.
array([ 0.48273727, -1.28739284,  1.52422575, -1.73666091, -0.25126809,
       -0.41952278, -0.75042054, -0.64585434, -0.86014472, -0.44542315])
You can calculate random numbers with a normal distribution (mean = 0, variance = 1) with random.randn ().
A = np.random.randn(10)
Execution result.
array([-0.94897439, -0.43075947,  0.088691  ,  0.37859721, -0.2141078 ,
        1.30327378,  0.41654781, -0.42907224, -1.61139916, -0.651694  ])
You can add by using the add method.
B = np.random.randn(10)
B
array([ 0.05623043,  1.97843447, -0.02581691,  0.70663108,  0.51213852,
       -0.70386143,  1.50729471, -0.00577632, -1.08456477, -0.38103167])
np.add(A,B)
Execution result.
array([ 0.5389677 ,  0.69104164,  1.49840884, -1.03002983,  0.26087043,
       -1.1233842 ,  0.75687417, -0.65163066, -1.94470949, -0.82645482])
You can subtract with the subtract method.
np.subtract(A,B)
Execution result.
array([ 0.42650684, -3.26582731,  1.55004266, -2.44329199, -0.76340661,
        0.28433865, -2.25771524, -0.64007803,  0.22442006, -0.06439147])
You can multiply with the multiply method.
np.multiply(A,B)
Execution result.
array([ 0.02714452, -2.54702237, -0.0393508 , -1.22717858, -0.12868407,
        0.2952859 , -1.1311049 ,  0.00373066,  0.93288266,  0.16972033])
You can divide with the divide method.
np.divide(A,A)
Execution result.
array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1.])
        Recommended Posts