相关疑难解决方法(0)

Python之间的坐标转换

是否有不同坐标系之间的转换功能?

例如,Matlab具有[rho,phi] = cart2pol(x,y)从笛卡尔坐标到极坐标的转换.好像它应该是numpy或scipy.

python coordinate-systems

41
推荐指数
6
解决办法
7万
查看次数

如何在Python中创建一个径向集群,如下面的代码示例?

我已经找到了几个关于如何创建这些确切的层次结构的示例(至少我相信它们是这样的),如下所示stackoverflow.com/questions/2982929/哪个很好用,几乎可以执行我正在寻找的内容.

[编辑]这是保罗代码的简化版本,现在应该更容易让某人帮助将其转换为径向集群而不是当前的集群形状

正确的结构,错误的显示 - 需要是一个径向集群

import scipy
import pylab
import scipy.cluster.hierarchy as sch

def fix_verts(ax, orient=1):
    for coll in ax.collections:
        for pth in coll.get_paths():
            vert = pth.vertices
            vert[1:3,orient] = scipy.average(vert[1:3,orient]) 

# Generate random features and distance matrix.
x = scipy.rand(40)
D = scipy.zeros([40,40])
for i in range(40):
    for j in range(40):
        D[i,j] = abs(x[i] - x[j])

fig = pylab.figure(figsize=(8,8))

# Compute and plot the dendrogram.
ax2 = fig.add_axes([0.3,0.71,0.6,0.2])
Y = sch.linkage(D, method='single')
Z2 = sch.dendrogram(Y)
ax2.set_xticks([])
ax2.set_yticks([])

fix_verts(ax2,0)
fig.savefig('test.png') …
Run Code Online (Sandbox Code Playgroud)

python numpy cluster-analysis dendrogram scipy

10
推荐指数
4
解决办法
1万
查看次数