divide(x1, x2, out=None, **kwargs)

Returns a true division of the inputs, element-wise.


This operator now supports automatic type promotion. The resulting type will be determined according to the following rules:

  • If both inputs are of floating number types, the output is the more precise type.

  • If only one of the inputs is floating number type, the result is that type.

  • If both inputs are of integer types including boolean, the output is of float32 or float64 type, which depends on your current default dtype:

    • When npx.is_np_default_dtype() returns False, default dtype is float32.

    • When npx.is_np_default_dtype() returns True, default dtype is float64.

  • x1 (ndarray or scalar) – Dividend array.

  • x2 (ndarray or scalar) – Divisor array.

  • out (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.


out – This is a scalar if both x1 and x2 are scalars.

Return type

ndarray or scalar


>>> np.true_divide(x, 4)
array([0.  , 0.25, 0.5 , 0.75, 1.  ])