Reputation: 25
I am teaching myself all kinds of things at once, which is probably problematic, but I am doing it by simultaneously trying to understand the source code in a library whilst using the same library. In the Spectral Python library there is this function:
def unmix(data, members):
'''
Perform linear unmixing on image data.
USAGE: mix = unmix(data, members)
ARGUMENTS:
data The MxNxB image data to be unmixed
members An CxB array of C endmembers
RETURN VALUE:
mix An MxNxC array of endmember fractions.
unmix performs linear unmixing on the image data. After calling the
function, mix[:,:,i] will then represent the fractional abundances
for the i'th endmember. If the result of unmix is returned into 'mix',
then an array of indices of greatest fractional endmembers is obtained
by argmax(mix).
Note that depending on endmembers given, fractional abundances for
endmembers may be negative.
'''
assert members.shape[1] == data.shape[2], \
'Matrix dimensions are not aligned.'
members = members.astype(float)
# Calculate the pseudo inverse
pi = np.dot(members, np.transpose(members))
pi = np.dot(np.linalg.inv(pi), members) #hacked by rr, bug report sent
(M, N, B) = data.shape
unmixed = np.zeros((M, N, members.shape[0]), float)
for i in range(M):
for j in range(N):
unmixed[i, j] = np.dot(pi, data[i, j].astype(float))
return unmixed
And i can understand what it is doing (within my limited understanding of linear algebra), but I cannot fathom the \ character following the line assert members.shape[1] == data.shape[2], \
.
Upvotes: 1
Views: 38