jax.numpy.negative#

jax.numpy.negative = <jnp.ufunc 'negative'>#

傳回輸入的逐元素負值。

JAX 實作的 numpy.negative

參數:
  • x – 輸入陣列或純量。

  • args (ArrayLike)

  • out (None)

  • where (None)

傳回值:

一個與 x 具有相同形狀和 dtype 的陣列,包含 -x

傳回類型:

Any

參見

注意

jnp.negative 應用於 unsigned integer 時,會產生其二補數負值的結果,這通常會由於整數下溢而導致意外的大正值。

範例

對於實數值輸入

>>> x = jnp.array([0., -3., 7])
>>> jnp.negative(x)
Array([-0.,  3., -7.], dtype=float32)

對於複數輸入

>>> x1 = jnp.array([1-2j, -3+4j, 5-6j])
>>> jnp.negative(x1)
Array([-1.+2.j,  3.-4.j, -5.+6.j], dtype=complex64)

對於 unit32

>>> x2 = jnp.array([5, 0, -7]).astype(jnp.uint32)
>>> x2
Array([         5,          0, 4294967289], dtype=uint32)
>>> jnp.negative(x2)
Array([4294967291,          0,          7], dtype=uint32)