我有动物位置(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),其中包含具有代表性的示例数据和预期输出。那样你就更有可能得到更好的答案,速度更快。 –