numpoly.result_type¶
- numpoly.result_type(*arrays_and_dtypes: Union[numpoly.typing.PolyLike, numpy.dtype[Any], None, Type[Any], numpy._typing._dtype_like._SupportsDType[numpy.dtype[Any]], str, Tuple[Any, int], Tuple[Any, Union[SupportsIndex, Sequence[SupportsIndex]]], List[Any], numpy._typing._dtype_like._DTypeDict, Tuple[Any, Any]]) → numpy.dtype[source]¶
Return the type that results from applying type promotion rules.
Type promotion in NumPy works similarly to the rules in languages like C++, with some slight differences. When both scalars and arrays are used, the array’s type takes precedence and the actual value of the scalar is taken into account.
For example, calculating 3*a, where a is an array of 32-bit floats, intuitively should result in a 32-bit float output. If the 3 is a 32-bit integer, the NumPy rules indicate it can’t convert losslessly into a 32-bit float, so a 64-bit float should be the result type. By examining the value of the constant, ‘3’, we see that it fits in an 8-bit integer, which can be cast losslessly into the 32-bit float.
- Args:
- arrays_and_dtypes:
The operands of some operation whose result type is needed.
- Return:
The result type.
- Example:
>>> q0 = numpoly.variable(dtype="i1") >>> numpoly.result_type(3, numpy.arange(7, dtype="i1"), q0) dtype('int8') >>> numpoly.result_type('i4', 'c8') dtype('complex128') >>> numpoly.result_type(3.0, -2) dtype('float64')