w3resource

NumPy Data type: common_types() function

numpy.common_types() function

The common_types() function return a scalar type which is common to the input arrays.

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.

Version: 1.15.0

Syntax:

numpy.common_type(*arrays)

Parameter:

Name Description Required /
Optional
array1, array2, … : ndarrays Input arrays.

Return value:

out : data type code
Data type code.

Example: numpy.common_type() function

>>> import numpy as np
>>> np.common_type(np.arange(32, dtype=np.float32))
<class 'numpy.float32'>
>>> np.common_type(np.arange(32, dtype=np.float32), np.arange(5))
<class 'numpy.float64'>
>>> np.common_type(np.arange(5), np.array([55, 6.j]), np.array([55.0]))
<class 'numpy.complex128'>

Python - NumPy Code Editor:

Previous: result_type()
Next: obj2sctype()



Follow us on Facebook and Twitter for latest update.