E-TE0603 — Invalid axis specification

Error Type

Type Error

Phase

building expressions from Python

Python exception

TypeError (builtin)

Message

An `axis` must be a non-negative integer or a tuple/list of non-negative integers, but got `{value}`.

Possible fix: count axes from 0 (negative axes are not supported).

({value} is a repr of the offending axis value, truncated to 80 characters)

Cause

The axis= argument of a reduction — jm.sum, jm.prod, jm.min, jm.max, or the corresponding .sum(), .prod(), .min(), .max() methods — is neither a non-negative integer nor a tuple/list of non-negative integers. Floats, strings, and other objects trigger this error, and so do negative integers such as axis=-1: negative axes counting from the end are not supported. A tuple or list containing any non-conforming element is rejected as a whole, with the whole container shown in the message.

Fix

Pass the axes as 0-based non-negative integer positions, either a single one or a tuple/list of them:

jm.sum(A, axis=0)
jm.sum(A, axis=(0, 2))

To address the last axis, write its explicit non-negative position instead of -1.