0

I need to take the transpose of M, but every time I try, it just returns the same thing as M again. I am somewhat new when it comes to Python, so I can't see what the issue is.

I have tried using different codes (i.e. M.T, M.tranpose, etc.). I have made new, irrelevant matrices in a different script to make sure M.T works, and it does, so I don't see why it won't work in the main code.

def integrandtemp(s):
    K = 17.5
    r = 0.7
    x0 = 0.1

    t = 5
    x = K/(1+((K/x0)-1)*np.exp(-r*s))

    dxdK = (x0*x0-x0*x0*np.exp(-r*s))/((x0+K*np.exp(-r*s)-x0*np.exp(-r*s))**2)
    dxdr = (K*K*x0*s*np.exp(-r*s)-K*x0*x0*s*np.exp(-r*s))/((x0+K*np.exp(-r*s)-x0*np.exp(-r*s))**2)
    dxdx0 = (K*x0+K*K*np.exp(-r*s)-K*x0*np.exp(-r*s)-K*x0+K*x0*np.exp(-r*s))/((x0+K*np.exp(-r*s)-x0*np.exp(-r*s))**2)

    M = [dxdK, dxdr, dxdx0]
    M = np.array([M])

    transpose = M.T
    var = 0.16
    return (1/var)*M@transpose

F = integrate.quad(integrandtemp, 0, 10)
print(F)

newF = F[0]
print(newF)

F_inv = inv(newF)

There are no errors, but M and M.T return the same thing, which they should not. I do get an error when I try to take the inverse of F a few lines later (square matrix expected).

  • This is expected behaviour. See https://stackoverflow.com/questions/5954603/transposing-a-numpy-array Also: Please reduce your code to a minimal example. (See https://stackoverflow.com/help/minimal-reproducible-example) – pktl2k Jul 02 '19 at 06:35
  • Now the issue is that inv(F) cannot be calculated. It keeps saying that a square matrix is expected. I thought to try "return (1/var)*transpose@M" instead, but then I get the error that "only size-1 arrays can be converted to Python scalars." I have edited the code above to represent what I currently have now. – Amanda Lococo Jul 02 '19 at 17:00
  • I suggest to go one step back and understand what exactly you want to calculate and how. Then you can go ahead, cast your algorithm in code and check if you get the expected output. A single number is not a square matrix, hence the error. – pktl2k Jul 03 '19 at 06:22

0 Answers0