Issue
i have a code loop in the number of clusters and plot each point as I got with a different color after that it did scaling for those points using non-metric scaling to recreate the data in 2D
the code in mtalab as
cmap=colormap;
for i=1:10
ic=int8((i*64.)/(10*1.));
subplot(2,1,1)
hold on
plot(rho(icl(i)),delta(icl(i)),'o','MarkerSize',8,'MarkerFaceColor',cmap(ic,:),'MarkerEdgeColor',cmap(ic,:));
end
subplot(2,1,2)
disp('Performing 2D nonclassical multidimensional scaling')
Y1 = mdscale(dist, 2, 'criterion','metricstress');
plot(Y1(:,1),Y1(:,2),'o','MarkerSize',2,'MarkerFaceColor','k','MarkerEdgeColor','k');
the problem is that I need to do this in python so what I did like
for i in range(10):
fig.add_subplot(211)
print(rho[icl[i]],delta[icl[i]])
plt.scatter(rho[icl[i]],delta[icl[i]],marker='o')
plt.show()
fig.add_subplot(212)
print('Performing 2D nonclassical multidimensional scaling')
mds=manifold.MDS(max_iter=200, eps=1e-4, n_init=1, dissimilarity="precomputed")
Y1=mds.fit_transform(dist)
plt.plot(Y1[:,1],Y1[:,2],marker='o',markersize=2,markerfacecolor='black',markeredgecolor='black')
I removed colormap because I got problems with the class after more searching I didn't found the replacement for it .. but got this error
plt.plot(Y1[:,1],Y1[:,2],marker='o',markersize=2,markerfacecolor='black',markeredgecolor='black')
IndexError: index 2 is out of bounds for axis 1 with size 2
if there is anything I should add please tell me. I tried to illustrate the problem as I can
Solution
When converting code from Matlab to Python you need to remember that Matlab Array indices start from 1 whereas in Python it starts from 0.
In the code Y1[:,1],Y1[:,2]
the error explains that you are trying to index beyond the array size.
plt.plot(Y1[:,0],Y1[:,1],marker='o',markersize=2,markerfacecolor='black',markeredgecolor='black')
Answered By - yudhiesh
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.