Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace slice of a numpy array with values from another array

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?

like image 515
user3017048 Avatar asked Apr 08 '15 06:04

user3017048


1 Answers

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

zeros[60:210,60:210] = ones
like image 200
Jose Buraschi Avatar answered Oct 06 '22 00:10

Jose Buraschi