I have the 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 is : in the constant values I want to put the new padding for example :
print np.lib.pad(x,(1,1),mode='constant',constant_values = [1,2,3,4,5,6,7,8])
and output like :
[[1,2,3]
[8,1,4]
[7,6,5]]
This is a 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]
i = 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
i += s
total_array = np.rot90(total_array, -1)
print(total_array)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With