Skip to content

Commit

Permalink
Merge pull request #35 from UBC-SPL-MDS/fix-extend_all_channels
Browse files Browse the repository at this point in the history
fix: Change output dimensions so there are no 'channels'
  • Loading branch information
Radascript authored May 17, 2022
2 parents 12a5064 + 8c74952 commit 426b7e6
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/emgdecompy/emgdecompy.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ def extend_input_by_R(x, R):

def extend_all_channels(x_mat, R):
"""
Takes an array with dimensions m by k,
where m represents channels and k represents observations,
and "extends" it to return an array of shape m by R+1 by k.
Takes an array with dimensions M by K,
where M represents number of channels and K represents observations,
and "extends" it to return an array of shape M * (R+1) by K.
Parameters
----------
Expand All @@ -87,33 +87,35 @@ def extend_all_channels(x_mat, R):
Returns
-------
numpy.ndarray
m x (R+1) x k extended array.
M(R+1) x K extended array.
Examples
--------
>>> R = 5
>>> x_mat = np.array([[1, 2, 3, 4,], [5, 6, 7, 8,]])
>>> extend_input_all_channels(x_mat, 3)
array([[[1., 2., 3., 4.],
[0., 1., 2., 3.],
[0., 0., 1., 2.],
[0., 0., 0., 1.]],
[[5., 6., 7., 8.],
[0., 5., 6., 7.],
[0., 0., 5., 6.],
[0., 0., 0., 5.]]])
array([[1., 2., 3., 4.],
[0., 1., 2., 3.],
[0., 0., 1., 2.],
[0., 0., 0., 1.],
[5., 6., 7., 8.],
[0., 5., 6., 7.],
[0., 0., 5., 6.],
[0., 0., 0., 5.]])
"""
extended_x_mat = np.zeros([x_mat.shape[0], R + 1, x_mat.shape[1]])
extended_x_mat = np.zeros([x_mat.shape[0], (R + 1), x_mat.shape[1]])

for i, channel in enumerate(x_mat):
# Extend channel
extended_channel = extend_input_by_R(channel, R)

# Add extended channel to the overall matrix of extended channels
extended_x_mat[i] = extended_channel


# Reshape to get rid of channels
extended_x_mat = extended_x_mat.reshape(x_mat.shape[0] * (R + 1), x_mat.shape[1])

return extended_x_mat


Expand Down

0 comments on commit 426b7e6

Please sign in to comment.