Computer >> कंप्यूटर >  >> प्रोग्रामिंग >> Python

पायथन में एक स्केलर मान का न्यूनतम डेटा प्रकार खोजें

numpy.min_scalar() विधि न्यूनतम डेटा प्रकार ढूंढती है। पहला पैरामीटर वह मान है जिसका न्यूनतम डेटा प्रकार पाया जाना है। स्केलर के लिए, डेटा प्रकार को सबसे छोटे आकार और सबसे छोटे स्केलर प्रकार के साथ लौटाता है जो इसका मान रख सकता है। गैर-स्केलर सरणी के लिए, सदिश का dtype असंशोधित लौटाता है। फ़्लोटिंग पॉइंट मान पूर्णांकों के लिए अवनत नहीं होते हैं, और जटिल मान फ़्लोट करने के लिए अवनत नहीं होते हैं।

कदम

सबसे पहले, आवश्यक पुस्तकालय आयात करें -

import numpy as np

numpy.min_scalar() विधि न्यूनतम डेटा प्रकार ढूंढती है -

print("Using the min_scalar() method in Numpy\n")
print("Result...",np.min_scalar_type(55))
print("Result...",np.min_scalar_type(38.9))
print("Result...",np.min_scalar_type(-78))
print("Result...",np.min_scalar_type(479))
print("Result...",np.min_scalar_type(2e100))
print("Result...",np.min_scalar_type(-45.8))
print("Result...",np.min_scalar_type(6.5e100))

उदाहरण

# For scalar, returns the data type with the smallest size and smallest scalar kind which can hold its value.
# For non-scalar array, returns the vector’s dtype unmodified.
# Floating point values are not demoted to integers, and complex values are not demoted to floats.

import numpy as np

# The numpy.min_scalar() method finds the minimal data type.
# The 1st parameter is the value whose minimal data type is to be found.
print("Using the min_scalar() method in Numpy\n")
print("Result...",np.min_scalar_type(55))
print("Result...",np.min_scalar_type(38.9))
print("Result...",np.min_scalar_type(-78))
print("Result...",np.min_scalar_type(479))
print("Result...",np.min_scalar_type(2e100))
print("Result...",np.min_scalar_type(-45.8))
print("Result...",np.min_scalar_type(6.5e100))

आउटपुट

Using the min_scalar() method in Numpy

Result... uint8
Result... float16
Result... int8
Result... uint16
Result... float64
Result... float16
Result... float64

  1. पायथन में नकारात्मक अनंत के निकटतम मूल्य कैसे प्राप्त करें?

    यद्यपि अनंत का कोई ठोस प्रतिनिधित्व नहीं है, ऋणात्मक अनंत की निकटतम संख्या को -inf तर्क के साथ फ्लोट() फ़ंक्शन के वापसी मान के रूप में दर्शाया जाता है >>> a=float('-inf') >>> -inf

  1. पायथन में सकारात्मक अनंत के निकटतम मूल्य कैसे प्राप्त करें?

    यद्यपि अनंत का कोई ठोस प्रतिनिधित्व नहीं है, अनंत के निकटतम संख्या को inf के साथ तर्क के रूप में फ्लोट() फ़ंक्शन के वापसी मान के रूप में दर्शाया जाता है >>> a=float('inf') >>> a inf

  1. पायथन में फ़ाइल का माइम प्रकार कैसे खोजें?

    पायथन में mimetypes नामक एक मॉड्यूल होता है जिसका उपयोग आप Python में फ़ाइल के माइम प्रकार का अनुमान लगाने के लिए कर सकते हैं। हालाँकि यह किसी फ़ाइल के माइम प्रकार को जानने का एक विश्वसनीय तरीका नहीं है। उदाहरण >>> import mimetypes >>> print(mimetypes.MimeTypes().guess_type('m