পাইথনে আমরা বিভিন্ন ম্যাট্রিক্স ম্যানিপুলেশন এবং অপারেশন সমাধান করতে পারি। Numpy মডিউল ম্যাট্রিক্স অপারেশনের জন্য বিভিন্ন পদ্ধতি প্রদান করে।
যোগ করুন() - দুটি ম্যাট্রিসের উপাদান যোগ করুন।
বিয়োগ() - দুটি ম্যাট্রিসের উপাদান বিয়োগ করুন।
বিভাজন() - দুটি ম্যাট্রিসের উপাদান ভাগ করুন।
গুণ করুন() − দুটি ম্যাট্রিসের উপাদানকে গুণ করুন।
ডট() − এটি ম্যাট্রিক্স গুন সঞ্চালন করে, উপাদান অনুযায়ী গুণন করে না।
sqrt() − ম্যাট্রিক্সের প্রতিটি উপাদানের বর্গমূল।
যোগফল(x,অক্ষ) - ম্যাট্রিক্সের সমস্ত উপাদান যোগ করুন। দ্বিতীয় যুক্তিটি ঐচ্ছিক, এটি ব্যবহার করা হয় যখন আমরা অক্ষ 0 হলে কলামের যোগফল এবং অক্ষ 1 হলে সারি যোগফল গণনা করতে চাই।
"T" - এটি নির্দিষ্ট ম্যাট্রিক্সের স্থানান্তর সম্পাদন করে।
উদাহরণ কোড
import numpy
# Two matrices are initialized by value
x = numpy.array([[1, 2], [4, 5]])
y = numpy.array([[7, 8], [9, 10]])
# add()is used to add matrices
print ("Addition of two matrices: ")
print (numpy.add(x,y))
# subtract()is used to subtract matrices
print ("Subtraction of two matrices : ")
print (numpy.subtract(x,y))
# divide()is used to divide matrices
print ("Matrix Division : ")
print (numpy.divide(x,y))
print ("Multiplication of two matrices: ")
print (numpy.multiply(x,y))
print ("The product of two matrices : ")
print (numpy.dot(x,y))
print ("square root is : ")
print (numpy.sqrt(x))
print ("The summation of elements : ")
print (numpy.sum(y))
print ("The column wise summation : ")
print (numpy.sum(y,axis=0))
print ("The row wise summation: ")
print (numpy.sum(y,axis=1))
# using "T" to transpose the matrix
print ("Matrix transposition : ")
print (x.T)
আউটপুট
Addition of two matrices: [[ 8 10] [13 15]] Subtraction of two matrices : [[-6 -6] [-5 -5]] Matrix Division : [[0.14285714 0.25 ] [0.44444444 0.5 ]] Multiplication of two matrices: [[ 7 16] [36 50]] The product of two matrices : [[25 28] [73 82]] square root is : [[1. 1.41421356] [2. 2.23606798]] The summation of elements : 34 The column wise summation : [16 18] The row wise summation: [15 19] Matrix transposition : [[1 4] [2 5]]