jax-ml/jax · error · TypeError
Cannot interpret ' ' as a data type.\n\nDid you…
Error message
Cannot interpret '{dtype}' as a data type.\n\nDid you accidentally write `jax.numpy.ones({shape}, {dtype})` when you meant `jax.numpy.ones(({shape}, {dtype}))`, i.e. with a single tuple argument for the shape? What it means
jnp.ones (via the shared shape/dtype checking helper) received a dtype argument that cannot be interpreted as a dtype — commonly because shape and dtype were passed as two positional arguments where a single tuple was intended. The hint shows the likely parenthesization fix.
Solutions
- Pass shape and dtype as separate arguments: jnp.ones((2, 3), jnp.float32)
Example fix
# before a = jnp.ones((2, 3, jnp.float32)) # after a = jnp.ones((2, 3), jnp.float32)
Defensive patterns
Strategy: validation
Validate before calling
assert all(isinstance(d, int) for d in shape), 'dtype accidentally inside shape tuple?'
Type guard
null
Try / catch
null
Prevention
- Separate dtype from shape arguments
- Use a linter rule flagging dtype objects inside shape tuples
When it happens
Trigger: jnp.ones((2, 3, dtype)) — one tuple argument mixing shape dims with a dtype.
Common situations: Editing or templating shape/dtype on one line and misplacing the parenthesis; porting torch-style size/dtype calls.
Related errors
- Cannot interpret ' ' as a data type.\n\nDid you…
- Cannot interpret ' ' as a data type.\n\nDid you…
- Attempting to convert array of shape
- Not implemented: bitcast 1D
- Not implemented: the 2nd minor dim can not be perfectly…
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/2d1e60fe97195d8f.
Report an issue: GitHub.
Appendix: source
Thrown at jax/_src/numpy/array_creation.py:138
See also:
- :func:`jax.numpy.ones_like`
- :func:`jax.numpy.empty`
- :func:`jax.numpy.zeros`
- :func:`jax.numpy.full`
Examples:
>>> jnp.ones(4)
Array([1., 1., 1., 1.], dtype=float32)
>>> jnp.ones((2, 3), dtype=bool)
Array([[ True, True, True],
[ True, True, True]], dtype=bool)
.. _explicit sharding: https://docs.jax.dev/en/latest/parallel.html
"""
if isinstance(shape, types.GeneratorType):
raise TypeError("expected sequence object with len >= 0 or a single integer")
if (m := _check_forgot_shape_tuple("ones", shape, dtype)): raise TypeError(m)
shape = canonicalize_shape(shape)
dtype = dtypes.check_and_canonicalize_user_dtype(
float if dtype is None else dtype, "ones")
sharding = util.choose_device_or_out_sharding(
device, out_sharding, 'jnp.ones')
return lax.full(shape, 1, dtype, sharding=sharding)
@export
def empty(shape: Any, dtype: DTypeLike | None = None, *,
device: xc.Device | Sharding | None = None,
out_sharding: NamedSharding | P | None = None) -> Array:
"""Create an empty array.
JAX implementation of :func:`numpy.empty`. Starting in JAX v0.11.0, this
returns an uninitialized array on platforms that support doing so. Prior to
v0.11.0, this function returned an array filled with zeros on all platforms.
View on GitHub (pinned to 1e1c6a8fc0)