
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 33676 Articles for Programming

290 Views
To get the machine limits information for integer types, use the numpy.iinfo() method in Python Numpy. The first parameter is the int_type i.e. the kind of integer data type to get information about.StepsAt first, import the required library −import numpy as npThe min is the minimum value of given dtype and max is the minimum value of given dtype.Checking for int16 type −a = np.iinfo(np.int16) print("Minimum of int16 type...", a.min) print("Maximum of int16 type...", a.max)Checking for int32 type −b = np.iinfo(np.int32) print("Minimum of int32 type...", b.min) print("Maximum of int32 type...", b.max)Checking for int64 type −c = np.iinfo(np.int64) print("Minimum of int64 ... Read More

284 Views
To return the scalar dtype or NumPy equivalent of Python type of an object, use the numpy.obj2sctype() method. The 1st parameter is the object of which the type is returned The default parameter, if given, is returned for objects whose types cannot be determined. If not given, None is returned for those objects.StepsAt first, import the required library −import numpy as npTo return the scalar dtype or NumPy equivalent of Python type of an object, use the numpy.obj2sctype() method −print("Using the obj2sctype() method in Numpy")Checking for int −print("Result...", np.obj2sctype(np.array([45, 89]))) print("Result...", np.obj2sctype(np.array([389, 7985])))Checking for float −print("Result...", np.obj2sctype(np.float32)) print("Result...", np.obj2sctype(np.float64)) print("Result...", ... Read More

455 Views
To return a scalar type which is common to the input arrays, use the numpy.common_type() method in Python Numpy. The 1st parameter is the input array(s). The return type will always be an inexact (i.e. floating point) scalar type, even if all the arrays are integer arrays. If one of the inputs is an integer array, the minimum precision type that is returned is a 64-bit floating point dtype.All input arrays except int64 and uint64 can be safely cast to the returned dtype without loss of information.StepsAt first, import the required library −import numpy as npTo return a scalar type ... Read More

168 Views
The numpy.can_cast() method returns True if array scalar and data type can occur according to the casting rule. The 1st parameter is the scalar or data type or array to cast from. The 2nd parameter is the data type to cast to.StepsAt first, import the required library −import numpy as npChecking if array scalar and data type can occur according to the casting rule −print("Checking with can_cast() method in Numpy") print("Result...", np.can_cast(np.array(20), 'i1')) print("Result...", np.can_cast(np.array(280), 'i1')) print("Result...", np.can_cast(np.array(80), 'u1')) print("Result...", np.can_cast(np.array(300.7), np.float32)) print("Result...", np.can_cast(np.array(120.6), np.float64)) print("Result...", np.can_cast(np.array(7.2e100), np.float32)) print("Result...", np.can_cast(np.array(6.5e100), np.float64))Exampleimport numpy as np # The numpy.can_cast() method returns ... Read More

185 Views
To convert an array of datetimes into an array of strings, use the numpy.datetime_as_string() method in Python Numpy. The method returns an array of strings the same shape as the input array. The first parameter is the array of UTC timestamps to format.The second parameter is the "timezone", the Timezone information to use when displaying the datetime. If ‘UTC’, end with a Z to indicate UTC time. If ‘local’, convert to the local timezone first, and suffix with a +-#### timezone offset. If a tzinfo object, then do as with ‘local’, but use the specified timezone.StepsAt first, import the required ... Read More

321 Views
To return the base 2 logarithm of the input array, use the numpy.log2() method in Python Numpy The method returns Base-2 logarithm of x. This is a scalar if x is a scalar. The 1st parameter, x is the input value, array-like. The 2nd parameter is out, a location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly allocated array is returned. A tuple (possible only as a keyword argument) must have length equal to the number of outputs.The 3rd parameter is where, the ... Read More

197 Views
To determine common type following standard coercion rules, use the numpy.find_common_type() method in Python numpy. The 1st argument is a list of dtypes or dtype convertible objects representing arrays. The 2nd argument is A list of dtypes or dtype convertible objects representing scalars.The find_common_type() method returns the common data type, which is the maximum of array_types ignoring scalar_types, unless the maximum of scalar_types is of a different kind (dtype.kind). If the kind is not understood, then None is returned.StepsAt first, import the required library −import numpy as npUsing the find_common_type() method in Numpy. Determine common type following standard coercion rules ... Read More

840 Views
To return the base 2 logarithm of the input array, use the numpy.log2() method in Python Numpy The method returns Base-2 logarithm of x. This is a scalar if x is a scalar. The 1st parameter, x is the input value, array-like. The 2nd parameter is out, a location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshlyallocated array is returned. A tuple must have length equal to the number of outputs.The 3rd parameter is where, the condition is broadcast over the input. At ... Read More

560 Views
The natural logarithm log is the inverse of the exponential function, so that log(exp(x)) = x. The natural logarithm is logarithm in base e. The method returns the natural logarithm of x, element-wise. This is a scalar if x is a scalar. The 1st parameter is the input value, array-like. The 2nd parameter is out, a location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated array is returned. A tuple (possible only as a keyword argument) must have length equal to the number ... Read More

537 Views
To convert an array of datetimes into an array of strings, use the numpy.datetime_as_string() method in Python Numpy. The method returns an array of strings the same shape as the input array. The first parameter is the array of UTC timestamps to format. The second parameter is the "timezone", the Timezone information to use when displaying the datetime. If ‘UTC’, end with a Z to indicate UTC time.StepsAt first, import the required library −import numpy as npCreate an array of datetime. The 'M' type specifies datetime −arr = np.arange('2022-02-20T03:25', 6*60, 60, dtype='M8[m]')Displaying our array −print("Array...", arr)Get the datatype −print("Array datatype...", ... Read More