python - Pad numpy array with fixed array as constant -


i have following code :

x = np.array([[1]]) print x print np.lib.pad(x,(1,1),mode='constant',constant_values=[4,8]) 

output :

[[1]] [[4 4 8] [4 1 8] [4 8 8]] 

the problem : in constant values want put new padding example :

print np.lib.pad(x,(1,1),mode='constant',constant_values = [1,2,3,4,5,6,7,8]) 

and output :

[[1,2,3] [8,1,4] [7,6,5]] 

this reverse engineering of print two-dimensional array in spiral order:

inner_array = np.array([3, 6, 7, 2]) outer_array = np.array([0, 23, 3, 5, 6, 8, 99, 73, 18, 42, 67, 88, 91, 12])  total_array = inner_array[::-1][np.newaxis] = 0 while true:     s = total_array.shape[1]     try:         total_array = np.vstack([total_array, outer_array[i:i+s]])     except valueerror:         break     try:         total_array = np.rot90(total_array, -1)     except valueerror:         pass     += s total_array = np.rot90(total_array, -1) print(total_array) 

Comments