簡體   English   中英

如何找到與二維數組對應的索引 position?

[英]How can I find the index position corresponding to a 2D array?

我有一個 .stl 文件和一個 .txt 文件,這兩個文件都需要讀取 xyz 值(又名點坐標)。 stl文件的坐標值包含txt文件的坐標值。 如何在stl文件中的txt文件中找到每個坐標值對應的position(即索引)? 這是 my.py 代碼:

def find_sequence():
    mesh = pv.read("./data/bai--LL-去掉下表面.stl")
    vertex = np.around(np.array(mesh.points), decimals=4)
    data = np.around(read_data("./data/錨定點1.txt", 0, 3), decimals=4)
    index = []
    for i in range(len(data)):
        for j in range(len(vertex)):
            if np.array_equal(data[i, :], vertex[j, :]):
                index.append(j + 1)
    return index

我認為我的邏輯沒有問題,但它不能正常工作,請幫助我! 太感謝了!

只需將 np.array_equal() 替換為 np.allclose()。 因為數據有小數位數的問題,代碼如下:

for i in range(len(data)):
    for j in range(len(vertex)):
        if np.allclose(data[i, :], vertex[j, :]):
            index.append(j)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM