I using python with numpy to create an array filled with numbers from tuple, and set it up to be 4×4 matrix.
numbers = (-8, -3, -5, 0, 4, 5, 6, 10, 7,8, 9, 100, 10, 11, 12, 1000)
numbers_array = np.array(numbers).reshape(4, 4)
Then try to set insert x quantity of zeros before the last element of each row.
zeros_array = np.zeros((1,7))
numbers_final_array = np.insert(numbers_array, -1, zeros_array, 1)
print('numbers_final_arrayn', numbers_final_array)
When I declare the zeros_array
in that way I get the ValueError
. However I the declare the zeros_array
like this:
zeros_array = np.zeros((7,1))
It does work, isn’t it weird?
why does it happen?
I was expecting something like this at the first try.
numbers_final_array
[[ -8 -3 -5 0 0 0 0 0 0 0 0]
[ 4 5 6 0 0 0 0 0 0 0 10]
[ 7 8 9 0 0 0 0 0 0 0 100]
[ 10 11 12 0 0 0 0 0 0 0 1000]]
xgzvsx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.