1

I've got two variables: dim and terms. I'd like to use these variables to define an array. For example,

  • If dim=2 and terms=4, I'd like m=np.zeros((4,4))
  • If dim=3 and terms=4, I'd like m=np.zeros((4,4,4))
  • If dim=3 and terms=3, I'd like m=np.zeros((3,3,3))

I tried defining the argument using a string but it doesn't accept that.

1 Answer 1

4

You can use:

np.zeros((terms,) * dim)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.