python 列表操作模块_Python:使用模块laspy的列表理解问题

最近我明白了使用列表理解的巨大优势。我正在处理存储在一个特殊格式*.las文件中的几百万个点(x,y,z)。在python中,使用此格式有两种方法:Liblas module [http://www.liblas.org/tutorial/python.html][1] (in a C++/Python)

laspy module [http://laspy.readthedocs.org/en/latest/tut_part_1.html][2] (pure Python)

我对liblas有几个问题,我想测试一下laspy。在

在liblas中,我可以将列表理解用作:

^{pr2}$

在拉斯比,我无法想象如何做到这一点:from laspy.file import File

f = file.File(inFile, mode='r')

f

(f[0].X,f[0].Y)

(30839973, 696447860)

我尝试了几种组合:points = [(p.X,p.Y) for p in f]

但我得到了这个信息Traceback (most recent call last):

File "", line 1, in

AttributeError: Point instance has no attribute 'x'

我尝试使用大写而不是大写,因为Python区分大小写:>>> [(p.x,p.y) for p in f]

Traceback (most recent call last):

File "", line 1, in

AttributeError: Point instance has no attribute 'x'

>>> [(p.X,p.Y) for p in f]

Traceback (most recent call last):

File "", line 1, in

AttributeError: Point instance has no attribute 'X'

这是交互式提示:C:\Python27>python.exe

Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] on win

32

Type "help", "copyright", "credits" or "license" for more information.

>>> from laspy.file import File

>>> inFile="C:\\04-las_clip_inside_area\\Ku_018_class.las"

>>> f = File(inFile, None, 'r')

>>> f

>>> points = [(p.X,p.Y) for p in f]

Traceback (most recent call last):

File "", line 1, in

AttributeError: Point instance has no attribute 'X'

>>>

列表后的打印p是:print dir(p)

['__doc__', '__init__', '__module__', 'make_nice', 'pack', 'packer', 'reader', 'unpacked']

在循环格式中,我总是有相同的错误>>> for p in f:

... print dir(p)

... print p.X,p.Y

...

['__doc__', '__init__', '__module__', 'make_nice', 'pack', 'packer', 'reader', 'unpacked']

Traceback (most recent call last):

File "", line 3, in

AttributeError: Point instance has no attribute 'X'

使用nneonneo建议的代码import numpy as np

for p in f:

... points = np.array([f.X, f.Y]).T

我可以存储在数组中points

array([[ 30839973, 696447860],

[ 30839937, 696447890],

[ 30839842, 696447832],

...,

[ 30943795, 695999984],

[ 30943695, 695999922],

[ 30943960, 695999995]])

但是错过了创建列表理解的方法points = [np.array(p.X,p.Y).T for p in f]

Traceback (most recent call last):

File "", line 1, in

AttributeError: Point instance has no attribute 'X'

提前感谢你的帮助。

詹尼

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值