6

Say I've got two numpy arrays which were created this way:

zeros = np.zeros((270,270))
ones = np.ones((150,150))

How can I insert ones in zeros at position [60,60]? I want an array that looks like a "square in the square".

I've tried the following two options:

np.put(empty, [60,60], ones)
np.put(empty, [3541], ones)
np.put[empty, [60:210,60:210], ones)

but the latter yields invalid syntax and the first two don't work either. Has anyone got an idea how this could work?

1 Answer 1

8

This is one way you can replace values in zeros with ones.

zeros[60:210,60:210] = ones
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot! Sometimes things can be straightforward, too ;-)
Does this still work?

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.