Skip to content

Comments

accomodate array in embedDistanceMatrix#3

Open
kmayerb wants to merge 1 commit intoagartland:masterfrom
kmayerb:patch-1
Open

accomodate array in embedDistanceMatrix#3
kmayerb wants to merge 1 commit intoagartland:masterfrom
kmayerb:patch-1

Conversation

@kmayerb
Copy link

@kmayerb kmayerb commented May 6, 2021

accomodate array as input argument dmatDF in embedDistanceMatrix()
see issue #2 for explanation

utils/embedding.py

Lines 63 to 69 in b61935a

def embedDistanceMatrix(dmatDf, method='kpca', n_components=2, **kwargs):
"""Two-dimensional embedding of sequence distances in dmatDf,
returning Nx2 x,y-coords: tsne, isomap, pca, mds, kpca, sklearn-tsne"""
if isinstance(dmatDf, pd.DataFrame):
dmat = dmatDf.values
else:
dmat = dmatDf

Note that the upper portion of the function is meant to accomodate either numpy.array or pd.DataFrame passed to dmatDf, but if numpy array is supplied then L111 will raise an error:

xyDf = pd.DataFrame(xy[:, :n_components], index=dmatDf.index, columns=np.arange(n_components))

Example

embedDistanceMatrix(dmatDf = pd.DataFrame(tr.pw_beta[0:10,:][:,0:10]), method = "mds")

👍

embedDistanceMatrix(dmatDf = tr.pw_beta[0:10,:][:,0:10], method = "mds")

👎

AttributeError: 'numpy.ndarray' object has no attribute 'index'

accomodate array as input argument dmatDF in embedDistanceMatrix()
see issue agartland#2 for explanation




https://github.com/agartland/utils/blob/b61935a860838a0e70afde7c9ecf2c68f51a2c4b/embedding.py#L63-L69

Note that the upper portion of the function is meant to accomodate either numpy.array or pd.DataFrame passed to dmatDf, but if numpy array is supplied then L111 will raise an error:

https://github.com/agartland/utils/blob/b61935a860838a0e70afde7c9ecf2c68f51a2c4b/embedding.py#L111


Example
```python
embedDistanceMatrix(dmatDf = pd.DataFrame(tr.pw_beta[0:10,:][:,0:10]), method = "mds")
```
👍 

```python
embedDistanceMatrix(dmatDf = tr.pw_beta[0:10,:][:,0:10], method = "mds")
```
👎 
```
AttributeError: 'numpy.ndarray' object has no attribute 'index'
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant