I have a matrix of shape 256x256 to which I'm trying to find a line of best fit. This is an image by the way, so these are simply intensity values. Let's assume I want to find the line of best fit through all the intensities, how would I go about doing that? This link describes how to do so on a 3d dataset, using svd. However I'm a bit confused as to how that would be applied to my numpy array?
EDIT: Here's an example with random values of doubles that I've profiled with %timeit:
ran = [25,50,75,100,125]
for i in ran:
J = np.random.random((i,i))
y,x=np.indices(J.shape)
x = x.ravel()
y = y.ravel()
J=J.ravel()
data = np.concatenate((x[:, np.newaxis],
y[:, np.newaxis],
J[:, np.newaxis]),axis=1)
datamean = data.mean(axis=0)
print "Doing %d now" %i
%timeit U, S, V = np.linalg.svd(data - datamean)
I get the following output:
Doing 25 now
100 loops, best of 3: 10.4 ms per loop
Doing 50 now
1 loops, best of 3: 285 ms per loop
Doing 75 now
1 loops, best of 3: 3 s per loop
Doing 100 now
1 loops, best of 3: 5.83 s per loop
Doing 125 now
1 loops, best of 3: 15.1 s per loop
EDIT2: Here's my actual array. I just saved it in numpy's npy format