নামপাই (ইংরেজি: NumPy) বড়, এবং বহু ডাইমেনশনের অ্যারে ও ম্যাট্রিক্সের জন্য, সাথে সাথে উঁচু পর্যায়ের গাণিতিক ফাংশন এ অ্যারে সমূহের মধ্যে অপারেটের জন্য উন্নয়ন করা পাইথনের একটি লাইব্রেরি। নামপাইয়ের পূর্বপুরুষ নিউমেরিক জিম হুগুনিন অন্যকিছু উন্নয়নকারীর সহযোগিতায় তৈরী করেছিলেন। ২০০৫ সালে ত্রাভিস ওলিফ্যান্ট নামপাই তৈরী করেন। নামপাই একটি উন্মুক্ত উৎসের সফটওয়্যার এবং এর অনেক অবদানকারী রয়েছে।

নামপাই
মূল উদ্ভাবকত্রাভিস ওলিফ্যান্ট
উন্নয়নকারীসম্প্রদায়-চালিত প্রকল্প
প্রাথমিক সংস্করণনিউমেরিক হিশেবে, ১৯৯৫ (1995); নামপাই হিশেবে, ২০০৬ (2006)
স্থিতিশীল সংস্করণ
১.১৭.৪ / ১১ নভেম্বর ২০১৯; ৪ বছর আগে (2019-11-11)[১]
পূর্বরূপ সংস্করণ
১.১৮.০আরসি১ / ৬ ডিসেম্বর ২০১৯; ৪ বছর আগে (2019-12-06)[১]
রিপজিটরি উইকিউপাত্তে এটি সম্পাদনা করুন
যে ভাষায় লিখিতপাইথন, সি
অপারেটিং সিস্টেমক্রস-প্ল্যাটফর্ম
ধরনসংখ্যাগত বিশ্লেষণ
লাইসেন্সবিএসডি
ওয়েবসাইটnumpy.org উইকিউপাত্তে এটি সম্পাদনা করুন

উদাহরণ সমূহ সম্পাদনা

অ্যারে তৈরী করা
>>> import numpy as np
>>> x = np.array([1, 2, 3])
>>> x
array([1, 2, 3])
>>> y = np.arange(10)  # like Python's range, but returns an array
>>> y
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
প্রাথমিক অপারেশনসমূহ
>>> a = np.array([1, 2, 3, 6])
>>> b = np.linspace(0, 2, 4)  # create an array with four equally spaced points starting with 0 and ending with 2.
>>> c = a - b
>>> c
array([ 1.        ,  1.33333333,  1.66666667,  4.        ])
>>> a**2
array([ 1,  4,  9, 36])
ইউনিভার্সাল ফাংশনসমূহ
>>> a = np.linspace(-np.pi, np.pi, 100) 
>>> b = np.sin(a)
>>> c = np.cos(a)
লিনিয়ার আলজেবরা
>>> from numpy.random import rand
>>> from numpy.linalg import solve, inv
>>> a = np.array([[1, 2, 3], [3, 4, 6.7], [5, 9.0, 5]])
>>> a.transpose()
array([[ 1. ,  3. ,  5. ],
       [ 2. ,  4. ,  9. ],
       [ 3. ,  6.7,  5. ]])
>>> inv(a)
array([[-2.27683616,  0.96045198,  0.07909605],
       [ 1.04519774, -0.56497175,  0.1299435 ],
       [ 0.39548023,  0.05649718, -0.11299435]])
>>> b =  np.array([3, 2, 1])
>>> solve(a, b)  # solve the equation ax = b
array([-4.83050847,  2.13559322,  1.18644068])
>>> c = rand(3, 3) * 20  # create a 3x3 random matrix of values within [0,1] scaled by 20
>>> c
array([[  3.98732789,   2.47702609,   4.71167924],
       [  9.24410671,   5.5240412 ,  10.6468792 ],
       [ 10.38136661,   8.44968437,  15.17639591]])
>>> np.dot(a, c)  # matrix multiplication
array([[  53.61964114,   38.8741616 ,   71.53462537],
       [ 118.4935668 ,   86.14012835,  158.40440712],
       [ 155.04043289,  104.3499231 ,  195.26228855]])
>>> a @ c # Starting with Python 3.5 and NumPy 1.10
array([[  53.61964114,   38.8741616 ,   71.53462537],
       [ 118.4935668 ,   86.14012835,  158.40440712],
       [ 155.04043289,  104.3499231 ,  195.26228855]])
ওপেনসিভির সাথে কাজ
>>> import numpy as np
>>> import cv2
>>> r = np.reshape(np.arange(256*256)%256,(256,256))  # 256x256 pixel array with a horizontal gradient from 0 to 255 for the red color channel
>>> g = np.zeros_like(r)  # array of same size and type as r but filled with 0s for the green color channel
>>> b = r.T # transposed r will give a vertical gradient for the blue color channel
>>> cv2.imwrite('gradients.png', np.dstack([b,g,r]))  # OpenCV images are interpreted as BGR, the depth-stacked array will be written to an 8bit RGB PNG-file called 'gradients.png'
True

আরও পড়ুন সম্পাদনা

তথ্যসূত্র সম্পাদনা

  1. "মুক্তিসমূহ – numpy/numpy"। সংগ্রহের তারিখ ১৫ ডিসেম্বর ২০১৯গিটহাব-এর মাধ্যমে। 

বহিঃসংযোগ সম্পাদনা