
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 10476 Articles for Python

115 Views
The numpy.can_cast() method returns True if cast between data types can occur according to the casting rule. The 1st parameter is the 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 npUsing the can_cast() to check if cast between data types can occur according to the casting rule −print("Checking with can_cast() method in Numpy") print("Result...", np.can_cast(np.int32, np.int64)) print("Result...", np.can_cast(np.float64, complex)) print("Result...", np.can_cast(complex, float)) print("Result...", np.can_cast('i8', 'f8')) print("Result...", np.can_cast('i8', 'f4')) print("Result...", np.can_cast('i4', 'S4'))Exampleimport numpy as np # The numpy.can_cast() method returns True if cast ... Read More

3K+ 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 "units" parameter sets the datetime unit to change the precision.StepsAt first, import the required library −import numpy as npCreate an array of datetime. The 'M' type specifies datetime −arr = np.arange('2022-02-20T02:10', 6*60, 60, dtype='M8[m]')To convert an array of datetimes into an array of strings, use the numpy.datetime_as_string() method in Python Numpy −print("Result...", np.datetime_as_string(arr, unit ='m'))Exampleimport numpy ... Read More

463 Views
To get the hypotenuse, use the numpy.hypot() method in Python Numpy. The method returns the hypotenuse of the triangle(s). This is a scalar if both x1 and x2 are scalars. This method is equivalent to sqrt(x1**2 + x2**2), element-wise. If x1 or x2 is scalar_like, it is broadcast for use with each element of the other argument. The parameters are the leg of the triangle(s). If x1.shape != x2.shape, they must be broadcastable to a common shape.StepsAt first, import the required library −import numpy as npCreating an array with integer elements −arr = np.ones((3, 3), dtype=int)Displaying our array −print("Array...", arr)Get ... Read More

1K+ Views
The arctan is a multi-valued function: for each x there are infinitely many numbers z such that tan(z) = x. # The inverse tangent is also known as atan or tan^{-1}.The convention is to return the angle z whose real part lies in [-pi/2, pi/2]. For real-valued input data types, arctan always returns real output. For each value that cannot be expressed as a real number or infinity, it yields nan and sets the invalid floating point error flag. For complex-valued input, arctan is a complex analytic function that has [1j, infj] and [-1j, -infj] as branch cuts, and is ... Read More

4K+ Views
The arctan is a multi-valued function: for each x there are infinitely many numbers z such that tan(z) = x. The convention is to return the angle z whose real part lies in [-pi/2, pi/2]. The inverse tangent is also known as atan or tan^{-1}.For real-valued input data types, arctan always returns real output. For each value that cannot be expressed as a real number or infinity, it yields nan and sets the invalid floating point error flag. For complex-valued input, arctan is a complex analytic function that has [1j, infj] and [-1j, -infj] as branch cuts, and is continuous ... Read More

249 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 "units" parameter sets the datetime unit to change the precision. We have passed the hours unitStepsAt first, import the required library −import numpy as npCreate an array of datetime. The 'M' type specifies datetime −arr = np.arange('2022-02-20T02:10', 6*60, 60, dtype='M8[m]')Displaying our array −print("Array...", arr)Get the datatype: −print("Array datatype...", arr.dtype) Get the dimensions of the Array −print("Array ... Read More

580 Views
To compute the Hyperbolic sine, use the numpy.sinh() method in Python Numpy. The method is equivalent to 1/2 * (np.exp(x) - np.exp(-x)) or -1j * np.sin(1j*x). Returns the corresponding hyperbolic sine values. This is a scalar if x is a scalar. The 1st parameter, x is input array. The 2nd and 3rd parameters are optional.The 2nd parameter is an ndarray, 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. The 3rd parameter is the condition is broadcast over the ... Read More

2K+ Views
To convert a degree array to radians, use the numpy.deg2rad() method in Python Numpy. The method returns the corresponding angle in radians. This is a scalar if x is a scalar. The 1st parameter is an input angle in degrees. The 2nd and 3rd parameters are optional.The 2nd parameter is an ndarray, 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.The 3rd parameter is the condition is broadcast over the input. At locations where the condition is True, the ... Read More

325 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 "units" parameter sets the datetime unit to change the precision. We have passed the seconds unit.StepsAt first, import the required library −import numpy as npCreate an array of datetime. The 'M' type specifies datetime −arr = np.arange('2022-02-20T02:10', 6*60, 60, dtype='M8[m]')Displaying our array −print("Array...", arr)Get the datatype −print("Array datatype...", arr.dtype) Get the dimensions of the Array −print("Array ... Read More

271 Views
The numpy.min_scalar() method finds the minimal data type. The 1st parameter is the value whose minimal data type is to be found. 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.StepsAt first, import the required library −import numpy as npThe numpy.min_scalar() method finds the minimal data type −print("Using the min_scalar() method in Numpy") 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...", ... Read More