0

I've got the following array:

rxn_probability = [1. 0. 0.]

And I want to create another array, num_rxn, that has the same shape and size of rxn_probability, which contains a number of the reactions, so in this case num_rxn would be: [1, 2, 3]. Starting at 1 and increasing until it reaches the same size and shape of rxn_probability, so that if I change the size of rxn_probability the size and shape of num_rxn will automatically be changed.

So far I've tried:

num_rxn = np.array(range(len(rxn_probability + 1)))

(also tried using arange in a similar way)

But this outputs:

[0 1 2]

which isn't what I want because it doesn't start at 1 or end at 3.

I've been reading about numpy.empty_like but I'm not sure if that would be the best or right solution. Any ideas?

Cheers

1
  • How are you going to change the size of rxn_probability without creating a new object? Commented May 4, 2020 at 12:52

1 Answer 1

1

You can use np.arange and then reshape to fit the shape of rxn_probability:

num_rxn = np.arange(1, rxn_probability.size + 1).reshape(rxn_probability.shape)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.