{"record":{"id":"d6f8a89370f84f8b","repo":"jax-ml/jax","slug":"cannot-interpret-dtype-as-a-data-type-n-ndid","errorCode":null,"errorMessage":"Cannot interpret '{dtype}' as a data type.\\n\\nDid you accidentally write `jax.numpy.zeros({shape}, {dtype})` when you meant `jax.numpy.zeros(({shape}, {dtype}))`, i.e. with a single tuple argument for the shape?","messagePattern":"Cannot interpret '(.+?)' as a data type\\.\\\\n\\\\nDid you accidentally write `jax\\.numpy\\.zeros\\((.+?), (.+?)\\)` when you meant `jax\\.numpy\\.zeros\\(\\((.+?), (.+?)\\)\\)`, i\\.e\\. with a single tuple argument for the shape\\?","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/array_creation.py","lineNumber":89,"sourceCode":"\n  See also:\n    - :func:`jax.numpy.zeros_like`\n    - :func:`jax.numpy.empty`\n    - :func:`jax.numpy.ones`\n    - :func:`jax.numpy.full`\n\n  Examples:\n    >>> jnp.zeros(4)\n    Array([0., 0., 0., 0.], dtype=float32)\n    >>> jnp.zeros((2, 3), dtype=bool)\n    Array([[False, False, False],\n           [False, False, False]], dtype=bool)\n\n  .. _explicit sharding: https://docs.jax.dev/en/latest/parallel.html\n  \"\"\"\n  if isinstance(shape, types.GeneratorType):\n    raise TypeError(\"expected sequence object with len >= 0 or a single integer\")\n  if (m := _check_forgot_shape_tuple(\"zeros\", shape, dtype)): raise TypeError(m)\n  dtype = dtypes.check_and_canonicalize_user_dtype(\n      float if dtype is None else dtype, \"zeros\")\n  shape = canonicalize_shape(shape)\n  sharding = util.choose_device_or_out_sharding(\n      device, out_sharding, 'jnp.zeros')\n  return lax.full(shape, 0, dtype, sharding=sharding)\n\n\n@export\ndef ones(shape: Any, dtype: DTypeLike | None = None, *,\n         device: xc.Device | Sharding | None = None,\n         out_sharding: NamedSharding | P | None = None) -> Array:\n  \"\"\"Create an array full of ones.\n\n  JAX implementation of :func:`numpy.ones`.\n\n  Args:\n    shape: int or sequence of ints specifying the shape of the created array.","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/array_creation.py#L71-L107","documentation":"jnp.zeros detects the classic comma typo: jnp.zeros((2, 3), jnp.float32) written as jnp.zeros(2, 3, jnp.float32) — no wait, the detected form is zeros((2, 3, float32)) style, i.e. packing dtype into the shape tuple so dtype becomes uninterpretable. When the shape tuple's extra element lands in the dtype slot, JAX raises with a hint about wrapping shape and dtype in one tuple.","triggerScenarios":"jnp.zeros((2, 3, jnp.float32)) — a single tuple argument containing both shape and dtype, so 'dtype' resolves to something like the shape tuple's last element and fails interpretation.","commonSituations":"Migrating from other frameworks (e.g. torch.empty(size, dtype) style) or a misplaced parenthesis when editing shape/dtype on one line.","solutions":["Split arguments: jnp.zeros((2, 3), jnp.float32)","If you intended one tuple, keep it shape-only and pass dtype separately"],"exampleFix":"# before\na = jnp.zeros((2, 3, jnp.float32))\n# after\na = jnp.zeros((2, 3), jnp.float32)","handlingStrategy":"validation","validationCode":"def check_shape_dtype_split(fn_name, shape, dtype):\n    # catches (2, 3, dtype) packed into shape\n    return all(isinstance(s, (int, np.integer)) for s in shape)","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Keep shape and dtype as separate arguments","Code-review single-tuple array creation calls"],"tags":["jax","shape-validation","dtype","typo-detection"],"backgroundTag":"invalid-shape-argument","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}