m0_as
m0_as

Reputation: 531

Access to an array using a list

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?

Upvotes: 0

Views: 34

Answers (1)

wim
wim

Reputation: 362497

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

A[tuple(b)] = c

Upvotes: 2

Related Questions