I am a newbie using Python.
I want to create a square matrix, let say 4X4, which the entries are taken from a vector, with length 16. This vector entry will be arranged in the column of matrix. Suppose that u is a vector with length 16, and M is a matrix with size 4×4. Then, M(1,1)=u(1), M(2,1)=u(2), M(3,1)=u(3), M(4,1)=u(4), M(1,2)=u(5), M(2,2)=u(6), M(3,2)=u(7), and soon.
This is the code that I wrote in Pyhton:
import numpy as np
from ast import literal_eval
aa = 0
for j in range(Ny):
for i in range(Nx):
U0[i][j]=u0[i+aa]
if (i%Nx)==3:
aa=aa+4
else:
aa=aa
where Nx=Ny=4, and u0 is a vector with length 16.
After I run the code, this is the result:
:79: DeprecationWarning: Conversion of an array with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.)
U0[i][j]=u0[i+aa]
Can someone please help me interpretate this result? And what is wrong with my code? Thank you very much for the help.
Margi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.