NumPy > Array arithmetics & comparisons

Name
Code
Output
array1 = numpy.random.randint(10, size=(2, 3))
print ("array1 \n",array1)
array2 = numpy.random.randint(10, size=(2, 3))
print ("array2 \n",array2)
result = array1 + array2
print ("addition result \n",result)
array1 
 [[1 0 4]
 [7 0 1]]
array2 
 [[4 5 6]
 [5 7 9]]
addition result 
 [[ 5  5 10]
 [12  7 10]]
array = numpy.random.randint(360, size=(2, 3))
print ("array \n",array)
result = numpy.cos(array)
print ("cosinus result \n",result)
array 
 [[ 37 350 192]
 [303 125 285]]
cosinus result 
 [[ 0.76541405 -0.28363328 -0.93488971]
 [ 0.16296104  0.78771451 -0.63334253]]
array1 = numpy.random.randint(5, size=(2, 3))
print ("array1 \n",array1,)
array2 = numpy.random.randint(5, size=(3, 2))
print ("array2 \n",array2)
result = array1.dot(array2)
print ("dot product result \n",result)
array1 
 [[0 1 2]
 [0 4 3]]
array2 
 [[1 4]
 [1 0]
 [3 4]]
dot product result 
 [[ 7  8]
 [13 12]]
array = numpy.random.randint(10, size=(2, 3))
print ("array \n",array)
result = (array < 5)
print ("comparison result \n",result)
array 
 [[3 6 5]
 [0 7 1]]
comparison result 
 [[ True False False]
 [ True False  True]]
array = numpy.random.randint(5, size=(2, 3))
print ("array \n",array)
result = numpy.exp(array)
print ("exponential result \n",result)
array 
 [[4 4 2]
 [1 1 0]]
exponential result 
 [[ 54.59815003  54.59815003   7.3890561 ]
 [  2.71828183   2.71828183   1.        ]]
array = numpy.random.randint(10, size=(2, 3))
print ("array \n",array)
result = numpy.log(array)
print ("logarithm result \n",result)
array 
 [[4 1 9]
 [7 1 7]]
logarithm result 
 [[ 1.38629436  0.          2.19722458]
 [ 1.94591015  0.          1.94591015]]
array = numpy.random.randint(360, size=(2, 3))
print ("array \n",array)
result = numpy.sin(array)
print ("sinus result \n",result)
array 
 [[222 120 130]
 [179 178 315]]
sinus result 
 [[ 0.86895084  0.58061118 -0.93010595]
 [ 0.07072217  0.87757534  0.74513326]]
array = numpy.random.randint(5, size=(2, 3))
print ("array \n",array)
result = numpy.sqrt(array)
print ("square root result \n",result)
array 
 [[2 3 1]
 [4 3 3]]
square root result 
 [[ 1.41421356  1.73205081  1.        ]
 [ 2.          1.73205081  1.73205081]]
array1 = numpy.random.randint(5, size=(2, 3))
print ("array1 \n",array1)
array2 = array1.copy()
print ("array2 \n",array2)
array3 = array2 *2
print ("array3 \n",array3)
result1 = numpy.array_equal(array1, array2)
print ("array1 vs array2 \n",result1)
result2 = numpy.array_equal(array1, array3)
print ("array1 vs array3 \n",result2)
array1 
 [[3 1 1]
 [2 1 4]]
array2 
 [[3 1 1]
 [2 1 4]]
array3 
 [[6 2 2]
 [4 2 8]]
array1 vs array2 
 True
array1 vs array3 
 False
array1 = numpy.random.randint(5, size=(2, 3))
print ("array1 \n",array1)
array2 = numpy.random.randint(5, size=(1, 3))
print ("array2 \n",array2)
result = array1 + array2
print ("broadcasted sum result \n",result)
array1 
 [[1 2 1]
 [1 2 2]]
array2 
 [[4 0 3]]
broadcasted sum result 
 [[5 2 4]
 [5 2 5]]
array1 = numpy.random.randint(5, size=(2, 3))
print ("array1 \n",array1,)
array2 = numpy.random.randint(5, size=(2, 3))
print ("array2 \n",array2)
result = (array1 == array2)
print ("comparison result \n",result)
array1 
 [[0 4 1]
 [4 4 0]]
array2 
 [[3 4 1]
 [4 3 4]]
comparison result 
 [[False  True  True]
 [ True False False]]
array1 = numpy.random.randint(20, size=(2, 3))
print ("array1 \n",array1)
array2 = numpy.random.randint(20, size=(2, 3))
print ("array2 \n",array2)
result = array1 - array2
print ("subtraction result \n",result)
array1 
 [[15 18  7]
 [19 16  7]]
array2 
 [[ 0 16  9]
 [17  1  2]]
subtraction result 
 [[15  2 -2]
 [ 2 15  5]]
array1 = numpy.random.randint(10, size=(2, 3))
print ("array1 \n",array1)
array2 = numpy.random.randint(10, size=(2, 3))
print ("array2 \n",array2)
result = array1 / array2
print ("division result \n",result)
array1 
 [[6 8 2]
 [4 5 6]]
array2 
 [[1 4 3]
 [5 8 8]]
division result 
 [[ 6.          2.          0.66666667]
 [ 0.8         0.625       0.75      ]]
array1 = numpy.random.randint(10, size=(2, 3))
print ("array1 \n",array1,)
array2 = numpy.random.randint(10, size=(2, 3))
print ("array2 \n",array2)
result1 = array1 * array2
print ("multiplication result method 1 \n",result1)
result2 = numpy.multiply(array1,array2)
print ("multiplication result method 2 \n",result2)
array1 
 [[7 6 8]
 [9 1 6]]
array2 
 [[2 7 8]
 [6 9 4]]
multiplication result method 1 
 [[14 42 64]
 [54  9 24]]
multiplication result method 2 
 [[14 42 64]
 [54  9 24]]