我有動物位置(X,Y,Z)數據,我有樹數據(X,Y,Z)。我需要拉動動物位置周圍發生的所有XYZ樹的輸入 - 所以我需要將包含xyz動物位置的numpy數組與包含相同區域中樹的x y z點位置的numpy數組進行比較。我想把所有的xyz樹拉到點的4個單位半徑內,並寫了一個函數來完成它。但它實際上並不只是拉動動物位置周圍的樹木。它只是打印所有可能的樹。我怎麼能只拉動物點周圍的樹,然後把它們放到一個.txt文件中,我可以在另一個程序中使用它?我是新手編程和任何幫助,我可以得到非常感謝。Python:如何將numpy數組中的整數數據與另一個numpy數組中的整數數據進行比較,並將結果讀入.txt文件?
以下是我的代碼以#descriptions:
#using array instead of dataframe
import numpy as np
from laspy.file import File
#load and consolidate Veg Point Coordinates into one array
VegList = sorted(glob.glob('/Users/sophiathompson/Desktop/copys/Clips/*.las'))
VegListCoords = []
for f in VegList:
print(f)
Veg= File(filename = f, mode = "r") # Open the file # Eventually, this will need to be the actual .laz files
VegListCoords.append(np.vstack((Veg.x, Veg.y, Veg.z)).transpose())
print (VegListCoords)
XYZVegComplete = np.concatenate((VegListCoords), axis = 0)
#Load animal point locations (x, y, z .csv file) from clip 240967 into array
Animal240967 = np.loadtxt(fname='/Users/ST/Desktop/copys/CatTXTfiles/240967_CatsFt.csv', delimiter =',')
#Use to find all vegetation heights in a 4 unit diameter of each animal point (animalx, animaly). #'d out lines of code are my attempts to make something work
def near_Animal(animalx, animaly):
for x, y, z in XYZVegComplete:
r=2 #xy coordinates in ft
PointsNearAnml = []
if (x-animalx)**2 + (y-animaly)**2 >= r**2:
PracticeTxt=open("/Users/ST/Desktop/practicefilecreate.txt", "w")
print (x, y, z)
#print (x, y, z) >> PracticeTxt, x, y, z
#PracticeTxt.write('%d %d %d \n' % Points)
#PracticeTxt.write('%d %d %d \n' % x y z)
#Points= (x, y, z)
#with open("/Users/sophiathompson/Desktop/practicefilecreate.txt", "w") as PracticeTxt:
#print >> PracticeTxt, Points
#PracticeTxt.close
#Use to call near_Animal: gather Veg Points based on proximity to animal points (using arrays)-
for animalx, animaly in Animal240967:
near_Animal(animalx, animaly)
使用您提供的代碼並不容易。考慮創建一個[Minimum,Complete,and Verifiable Example](https://stackoverflow.com/help/mcve),其中包含具有代表性的示例數據和預期輸出。那樣你就更有可能得到更好的答案,速度更快。 –