1

I'm trying to delete a line from a .xyz file through numpy.delete () command, but is not working.

below is a part of the code problem. The code works without giving any error but the line is not deleted.

Thank you!

import numpy
import os

####################################################
a = numpy.loadtxt("0000_seg.xyz")
max_xyz = a.max(axis=0)
min_xyz = a.min(axis=0)
print max_xyz
print min_xyz
####################################################
ponto = numpy.loadtxt("0000_poucos.xyz")
####################################################

arquivos = os.listdir('/home/caye/Documentos/python/pontos')

print 'tamanho antes'
print len(ponto)

for arquivo in arquivos:
    try:
    for i in range(0,len(ponto)):
        for j in range(3):
            if ponto[i,j] > max_xyz[j]:
                print 'del max'
                numpy.delete(ponto, i)
            if ponto[i,j] < min_xyz[j]:
                print 'del min'
                numpy.delete(ponto, i)

    except:
        pass


print 'tamanho depois'
print len(ponto)
2
  • That try:except:pass is dangerous. It can hide all kinds of unexpected errors. What kind of error are you trying to capture or pass? Commented Mar 26, 2015 at 19:17
  • Iterative solutions like this are slow. Commented Mar 26, 2015 at 19:18

1 Answer 1

3

numpy.delete() is not an in-place operation, and returns a new copy of your array that has been operated on. As a result, ponto itself is never changed, you just return a changed copy of it and do nothing with it. Assign a new variable to your numpy.delete() statements, and print that. Also note try-except-pass is inherently evil and you could in fact have 100 things wrong in your code without knowing as it will hide all the errors.

You can find the documentation concerning numpy.delete which explains this behavior here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.