J'ai des données d'emplacements d'animaux (X, Y, Z) et j'ai des données d'arbre (X, Y, Z). J'ai besoin de tirer toutes les entrées d'arbres XYZ qui se produisent autour des emplacements d'animaux - donc j'ai besoin de comparer un tableau numpy contenant des emplacements d'animaux xyz à un tableau numpy contenant des emplacements ponctuels x y z d'arbres dans la même zone. Je veux tirer tous les arbres xyz dans un rayon de 4 unités et écrire une fonction pour le faire. Mais il ne fait pas que tirer les arbres autour des emplacements des animaux. il imprime juste tous les arbres possibles. Comment puis-je tirer seulement les arbres autour des points d'animaux et ensuite les mettre dans un fichier .txt que je peux utiliser dans un autre programme? Je suis nouveau à la programmation et toute aide que je peux obtenir est grandement appréciée.Python: Comment puis-je comparer des données entières dans un tableau numpy à des données entières dans un autre tableau numpy et lire les résultats dans un fichier .txt?
ce qui suit est mon code aveC#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)
Ce n'est pas facile de travailler avec le code que vous avez fourni. Envisagez de créer un [Exemple minimum, complet et vérifiable] (https://stackoverflow.com/help/mcve), avec des exemples de données représentatifs et une sortie attendue. Vous aurez plus de chances d'obtenir une meilleure réponse, plus rapidement, de cette façon. –