numpy.can_cast() পদ্ধতিটি True ফেরত দেয় যদি স্কেলার এবং ডেটা টাইপের মধ্যকার キャスト কাস্টিং নিয়ম অনুযায়ী সম্ভব হয়। প্রথম প্যারামিটার হল キャスト করার স্কেলার বা ডেটা টাইপ বা অ্যারে। দ্বিতীয় প্যারামিটার হল কাস্ট করার ডেটা টাইপ।
ধাপসমূহ
প্রথমে প্রয়োজনীয় লাইব্রেরি আমদানি করুন:
import numpy as np
can_cast() পদ্ধতিতে স্কেলার এবং ডেটা টাইপের মধ্যকার キャスト কাস্টিং নিয়ম অনুযায়ী সম্ভব কিনা যাচাই করুন:
print("Numpy-এ can_cast() পদ্ধতিতে যাচাই করুন\n")
print("ফলাফল...", np.can_cast(20, 'i1'))
print("ফলাফল...", np.can_cast(280, 'i1'))
print("ফলাফল...", np.can_cast(80, 'u1'))
print("ফলাফল...", np.can_cast(300.7, np.float32))
print("ফলাফল...", np.can_cast(120.6, np.float64))
print("ফলাফল...", np.can_cast(7.2e100, np.float32))
print("ফলাফল...", np.can_cast(6.5e100, np.float64))
সম্পূর্ণ উদাহরণ
import numpy as np
# numpy.can_cast() পদ্ধতিটি True ফেরত দেয় যদি স্কেলার এবং ডেটা টাইপের মধ্যকার キャスト
# কাস্টিং নিয়ম অনুযায়ী সম্ভব হয়।
# প্রথম প্যারামিটার হল キャスト করার স্কেলার বা ডেটা টাইপ বা অ্যারে।
# দ্বিতীয় প্যারামিটার হল কাস্ট করার ডেটা টাইপ।
print("Numpy-এ can_cast() পদ্ধতিতে যাচাই করুন\n")
print("ফলাফল...", np.can_cast(20, 'i1'))
print("ফলাফল...", np.can_cast(280, 'i1'))
print("ফলাফল...", np.can_cast(80, 'u1'))
print("ফলাফল...", np.can_cast(300.7, np.float32))
print("ফলাফল...", np.can_cast(120.6, np.float64))
print("ফলাফল...", np.can_cast(7.2e100, np.float32))
print("ফলাফল...", np.can_cast(6.5e100, np.float64))
আউটপুট
Numpy-এ can_cast() পদ্ধতিতে যাচাই করুন
ফলাফল... True
ফলাফল... False
ফলাফল... True
ফলাফল... True
ফলাফল... True
ফলাফল... False
ফলাফল... True