0

I have an array A and a list b. I want to put number c in the location b of array A. For example, assume

import numpy
size = 4
size_maker = [2] * size
A = numpy.zeros(shape=size_maker)

b = [0,1,0,0]
c = 20

I want to have A[0,1,0,0] = 20. Any idea?

2
  • 1
    In your example, A is a 4D array of one element. You probably wanted to use size_maker = [2] * size. Commented Apr 11, 2017 at 2:38
  • @DYZ you are right. Commented Apr 11, 2017 at 2:41

1 Answer 1

2

You just need to use a tuple instead of a list.

A[tuple(b)] = c
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.