{"record":{"id":"119efc5210dd3102","repo":"jax-ml/jax","slug":"jax-numpy-meshgrid-only-supports-copy-true","errorCode":null,"errorMessage":"jax.numpy.meshgrid only supports copy=True","messagePattern":"jax\\.numpy\\.meshgrid only supports copy=True","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/lax_numpy.py","lineNumber":6092,"sourceCode":"    [[1 2]]\n    >>> print(y_grid)\n    [[10]\n     [20]\n     [30]]\n\n    2D matrix-index mesh grid:\n\n    >>> x_grid, y_grid = jnp.meshgrid(x, y, indexing='ij')\n    >>> print(x_grid)\n    [[1 1 1]\n     [2 2 2]]\n    >>> print(y_grid)\n    [[10 20 30]\n     [10 20 30]]\n  \"\"\"\n  args = list(util.ensure_arraylike_tuple(\"meshgrid\", tuple(xi)))\n  if not copy:\n    raise ValueError(\"jax.numpy.meshgrid only supports copy=True\")\n  if indexing not in [\"xy\", \"ij\"]:\n    raise ValueError(f\"Valid values for indexing are 'xy' and 'ij', got {indexing}\")\n  if any(a.ndim != 1 for a in args):\n    raise ValueError(\"Arguments to jax.numpy.meshgrid must be 1D, got shapes \"\n                     f\"{[a.shape for a in args]}\")\n  if indexing == \"xy\" and len(args) >= 2:\n    args[0], args[1] = args[1], args[0]\n  shape = [1 if sparse else a.shape[0] for a in args]\n  _a_shape = lambda i, a: [*shape[:i], a.shape[0], *shape[i + 1:]] if sparse else shape\n  output = [lax.broadcast_in_dim(a, _a_shape(i, a), (i,)) for i, a, in enumerate(args)]\n  if indexing == \"xy\" and len(args) >= 2:\n    output[0], output[1] = output[1], output[0]\n  return tuple(output)\n\n\n@export\n@api.jit\ndef i0(x: ArrayLike) -> Array:","sourceCodeStart":6074,"sourceCodeEnd":6110,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/lax_numpy.py#L6074-L6110","documentation":"jnp.meshgrid does not support copy=False. NumPy's meshgrid can return views when copy=False, but JAX arrays have different view semantics under transformations, so JAX only implements the copying behavior and raises this ValueError for any falsy copy argument.","triggerScenarios":"Calling jnp.meshgrid(*xi, copy=False), typically ported from np.meshgrid(..., copy=False, sparse=True) memory-optimization patterns.","commonSituations":"Porting NumPy code that disabled copying to save memory on large grids; users assuming JAX supports the full np.meshgrid signature. Note jnp.meshgrid does support sparse=True for the same memory goal.","solutions":["Drop copy=False (use the default copy=True) and add sparse=True if memory is the concern","If only coordinate values matter, use jnp.broadcast_to on 1-D arrays to get logical grids without materialization"],"exampleFix":"// before\nX, Y = jnp.meshgrid(x, y, copy=False)\n// after\nX, Y = jnp.meshgrid(x, y, sparse=True)","handlingStrategy":"validation","validationCode":"out = jnp.meshgrid(*xi, sparse=True)  # never pass copy=False","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use sparse=True for memory savings instead of copy=False","Grep np.meshgrid call sites for copy=False when porting"],"tags":["jax","meshgrid","copy-semantics","valueerror"],"backgroundTag":"unsupported-kwarg-in-jax","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}