python - Seamlessly solve square linear system that could be 1-dimensional in numpy -


i solving linear system of equations ax=b. known a square , of full rank, result of few matrix multiplications, a = numpy.dot(c,numpy.dot(d,e)) in result can 1x1 depending on inputs c,d,e. in case a float.

b ensured vector, when 1x1 one.

i doing

a = numpy.dot(c,numpy.dot(d,e)) try:     x = numpy.linalg.solve(a,b) except:     x = b[0] / 

i searched numpy's documentation , didn't find other alternatives solve , dot accept scalars first or output arrays second. numpy.linalg.solve requires dimension @ least 2. if going produce a = numpy.array([5]) complain too.

is there alternative missed?

in result can 1x1 depending on inputs c,d,e. in case float.

this not true, 1x1 matrix, expected

x=np.array([[1,2]]) z=x.dot(x.t)  # 1x2 matrix times 2x1 print(z.shape) # (1, 1) 

which works fine linalg.solve

linalg.solve(z, z) # returns [[1]], expected 

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -