কম্পিউটার

Python-এর আর্গুমেন্টে NumPy টাইপ প্রচারের নিয়ম প্রয়োগ করার ফলে যে টাইপ পাওয়া যায় তা ফেরত দিন


numpy.result_type() পদ্ধতি আর্গুমেন্টে NumPy টাইপপ্রমোশন নিয়ম প্রয়োগ করার ফলে যে টাইপটি পাওয়া যায় তা প্রদান করে। 1ম প্যারামিটার হল কিছু অপারেশনের অপারেন্ড যার ফলাফলের প্রকার প্রয়োজন। NumPy-এ টাইপ প্রচার C++ এর মতো ভাষার নিয়মের মতোই কাজ করে, কিছু সামান্য পার্থক্য সহ। যখন স্কেলার এবং অ্যারে উভয়ই ব্যবহার করা হয়, তখন অ্যারের প্রকার অগ্রাধিকার নেয় এবং স্কেলারের প্রকৃত মান বিবেচনায় নেওয়া হয়।

পদক্ষেপ

প্রথমে, প্রয়োজনীয় লাইব্রেরি আমদানি করুন -

import numpy as np

numpy.result_type() পদ্ধতিটি সেই প্রকারটি প্রদান করে যা আর্গুমেন্টে NumPy টাইপপ্রমোশন নিয়ম প্রয়োগ করার ফলে ফলাফল হয় −

print("Using the result_type() method in Numpy\n")
print("Result...",np.result_type(2, np.arange(4,dtype='i1')))
print("Result...",np.result_type(5, 8))
print("Result...",np.result_type('i4', 'c8'))
print("Result...",np.result_type(3.8, 8))
print("Result...",np.result_type(5, 20.7))
print("Result...",np.result_type(-8, 20.7))
print("Result...",np.result_type(10.0, -4))

উদাহরণ

import numpy as np
# The numpy.result_type() method returns the type that results from applying the NumPy type promotion rules to the arguments.
# The 1st parameter is the operands of some operation whose result type is needed.
print("Using the result_type() method in Numpy\n")

print("Result...",np.result_type(2, np.arange(4,dtype='i1')))
print("Result...",np.result_type(5, 8))
print("Result...",np.result_type('i4', 'c8'))
print("Result...",np.result_type(3.8, 8))
print("Result...",np.result_type(5, 20.7))
print("Result...",np.result_type(-8, 20.7))
print("Result...",np.result_type(10.0, -4))

আউটপুট

Using the result_type() method in Numpy

Result... int8
Result... int64
Result... complex128
Result... float64
Result... float64
Result... float64
Result... float64

  1. Python Pandas - Index অবজেক্ট থেকে আপেক্ষিক ফ্রিকোয়েন্সি ফেরত দিন

  2. Python Pandas - Timedelta অবজেক্ট থেকে সেকেন্ড রিটার্ন করুন

  3. Python Pandas - Timedelta অবজেক্ট থেকে ন্যানোসেকেন্ড ফেরত দিন

  4. Python Pandas - Timedelta অবজেক্ট থেকে মাইক্রোসেকেন্ড রিটার্ন করুন