Mathematical operators on Numpy Array and List

import numpy as np

a = np.array([1, 2, 3])
print(type(a))           
print('Numpy Array:\n',a)
print('Addition of Numpy Arrays with constant:\n',a+13)
print('Addition of Numpy Arrays:\n',a+a)
print('Multiplication of Numpy Arrays with constant:\n',a*3)
print('Multiplication of Numpy Arrays with another:\n',a*a)
print('Divison of Numpy Arrays with constant:\n', a/3)
print('Divison of Numpy Arrays with another:\n', a/a)
print('Power of Numpy Arrays with constant:\n', a**4)
print('Power of Numpy Arrays with another:\n', a**a)
print('Remainder of Numpy Arrays with constant:\n',a%2)
print('Remainder of Numpy Arrays with another:\n',a%a)
print('Subtraction of Numpy Arrays with constant:\n', a-1)
print('Subtraction of Numpy Arrays with another:\n', a-a)

try:
  a1=[1, 2, 3]
  print('\n',type(a1))
  print('Common List:\n', a1)
  print('Addition of Lists:\n',a1+a1)
  print('Multiplication of List with constant:\n',a1*3)
  print(a1+13) #error
  print(a1*a1) #error
  print(a1/3) #error
  print(a1/a1) #error
  print(a1**4) #error
  print(a1*a1) #error
  print(a1%2) #error
  print(a1%a1) #error
  print(a1-1) #error
  print(a1-a1) #error
except TypeError:
  print('TypeError')
 

No comments: