Extracting Data from traced ConcreteArray #5789
Answered
by
jakevdp
vasilavramov
asked this question in
Q&A
-
How do I convert an array of type traced ConcreteArray to a normal numpy array? The normal np.array method fails. I.e. Is there any efficient way to extract the raw data from the concrete array? |
Beta Was this translation helpful? Give feedback.
Answered by
jakevdp
Feb 22, 2021
Replies: 1 comment 3 replies
-
You can use the import jax.numpy as jnp
from jax import grad
extracted_value = None
def add(a, b):
global extracted_value
extracted_value = a.val
return jnp.add(a, b)
_ = grad(add)(2.0, 10.)
print(extracted_value)
# 2.0 However, for most uses of JAX you should not need to do this. Can you say more about the application that inspired this question? |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
vasilavramov
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use the
val
attribute of theConcreteArray
to extract the concrete value; for example:However, for most uses of JAX you should not need to do this. Can you say more about the application that inspired this question?