Skip to content

jnp.pad: TypeError: iteration over a 0-d array #5550

Answered by jakevdp
bhchiang asked this question in Q&A
Discussion options

You must be logged in to vote

This is a misleading error (I'll plan to send a fix to improve it today), but as @BugQualia mentioned the issue is that you're padding with a dynamic value. One way to fix this is to mark the pad width as static:

@jax.partial(jax.jit, static_argnums=1)
def nlm(img, search_window):
  img_pad = jnp.pad(img, (search_window, search_window))
  img_pad = jnp.pad(img, search_window)

See JIT mechanics: tracing and static variables for some discussion of this.

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@jakevdp
Comment options

@bhchiang
Comment options

@jakevdp
Comment options

Answer selected by bhchiang
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants