Skip to content

Instantly share code, notes, and snippets.

@PortWhisperer
Last active February 19, 2019 02:43
Show Gist options
  • Save PortWhisperer/a54a4e876ec82ab2049e17559b9433ea to your computer and use it in GitHub Desktop.
Save PortWhisperer/a54a4e876ec82ab2049e17559b9433ea to your computer and use it in GitHub Desktop.
questions for #python
# how can i get just the values instead of the array objects ?
{
"cluster" + str(int(i) + 1): i
for i in clust_obj.predicted_clusters[["cluster"]].values[range(len(clust_obj.predicted_clusters))]
}
Out[40]:
{'cluster2': array([1]),
'cluster3': array([2]),
'cluster7': array([6]),
'cluster1': array([0]),
'cluster6': array([5]),
'cluster5': array([4]),
'cluster4': array([3])}
# attempt 2
{
"cluster" + str(int(i) + 1): i
for i in clust_obj.predicted_clusters[["cluster"]].values
}
Out[26]:
{'cluster2': array([1]),
'cluster3': array([2]),
'cluster7': array([6]),
'cluster1': array([0]),
'cluster6': array([5]),
'cluster5': array([4]),
'cluster4': array([3])}
# attempt 3
{
"cluster" + str(int(i) + 1): i
for i in clust_obj.predicted_clusters[["cluster"]].values[range(len(clust_obj.predicted_clusters))[0]]
}
Out[44]: {'cluster2': 1}
@PortWhisperer
Copy link
Author

solution:
cluster_labels = {
"cluster" + str(int(i) + 1): i[0]
for i in clust_obj.predicted_clusters[["cluster"]].values[range(len(clust_obj.predicted_clusters))]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment