English 中文(简体)
食谱
原标题:numpy genfromtxt columns

我的感觉是,从食肉类中产生一种极简单的问题。 这是我法典的简化版本:

import numpy as np

in_file_1 = raw_input ( enter name of template file to be scaled:
 )
spec_1 = np.genfromtxt(in_file_1, delimiter = [8,24], dtype =float)
print spec_1

阅读的档案完全简单,两栏没有标题等:

6392.01   0.90286163
6392.05   0.88731778
6392.09   0.87789831
6392.13   0.87716535
6392.16   0.88523003
6392.20   0.90948176
6392.24   0.93056874
6392.28   0.95782283
6392.32   0.98056805
6392.36   0.99623797
6392.39   0.99458828
6392.43   0.9848269
6392.47   0.96011146
6392.51   0.92864767

When I read the above using genfromtxt on the python command line it gives me the two column array as i expect:

>>> import numpy as np
>>> in_file_1 = raw_input ( enter name of template file to be scaled:
 )
enter name of template file to be scaledl_1714650_052_no_head.txt
>>> spec_1 = np.genfromtxt(in_file_1, delimiter = [8,24], dtype =float)
>>> spec_1
array([[  6.39201000e+03,   9.02861630e-01],
       [  6.39205000e+03,   8.87317780e-01],
       [  6.39209000e+03,   8.77898310e-01],
       [  6.39213000e+03,   8.77165350e-01],
       [  6.39216000e+03,   8.85230030e-01],
       [  6.39220000e+03,   9.09481760e-01],
       [  6.39224000e+03,   9.30568740e-01],
       [  6.39228000e+03,   9.57822830e-01],
       [  6.39232000e+03,   9.80568050e-01],
       [  6.39236000e+03,   9.96237970e-01],
       [  6.39239000e+03,   9.94588280e-01],
       [  6.39243000e+03,   9.84826900e-01],
       [  6.39247000e+03,   9.60111460e-01],
       [  6.39251000e+03,   9.28647670e-01]])
>>> 

但在担任该职位顶端的文字(阅读-测试.py)时,它只恢复一栏插图:

[scrooge:Acc_cont_removal/All_stars/Test] darryl% python read_test.py 
enter name of template file to be scaled:
l_1714650_052_no_head.txt
[[  6.39201000e+03   9.02861630e-01]
 [  6.39205000e+03   8.87317780e-01]
 [  6.39209000e+03   8.77898310e-01]
 [  6.39213000e+03   8.77165350e-01]
 [  6.39216000e+03   8.85230030e-01]
 [  6.39220000e+03   9.09481760e-01]
 [  6.39224000e+03   9.30568740e-01]
 [  6.39228000e+03   9.57822830e-01]
 [  6.39232000e+03   9.80568050e-01]
 [  6.39236000e+03   9.96237970e-01]
 [  6.39239000e+03   9.94588280e-01]
 [  6.39243000e+03   9.84826900e-01]
 [  6.39247000e+03   9.60111460e-01]
 [  6.39251000e+03   9.28647670e-01]]
[scrooge:Acc_cont_removal/All_stars/Test] darryl% 

我已尝试过各种限制人员组合,但我无法说明正在发生的情况,这部法典几天前就做了罚款。 在OSX(Lion)上运行,Python v2.7。

Any ideas gratefully received. Darryl

问题回答

你们的答案是正确的!

>>> numpy.genfromtxt( testfile , delimiter=[8,24], dtype = float)
array([[  6.39201000e+03,   9.02861630e-01],
       [  6.39205000e+03,   8.87317780e-01],
       [  6.39209000e+03,   8.77898310e-01],
       [  6.39213000e+03,   8.77165350e-01],
       [  6.39216000e+03,   8.85230030e-01],
       [  6.39220000e+03,   9.09481760e-01],
       [  6.39224000e+03,   9.30568740e-01],
       [  6.39228000e+03,   9.57822830e-01],
       [  6.39232000e+03,   9.80568050e-01],
       [  6.39236000e+03,   9.96237970e-01],
       [  6.39239000e+03,   9.94588280e-01],
       [  6.39243000e+03,   9.84826900e-01],
       [  6.39247000e+03,   9.60111460e-01],
       [  6.39251000e+03,   9.28647670e-01]])
>>> print _
[[  6.39201000e+03   9.02861630e-01]
 [  6.39205000e+03   8.87317780e-01]
 [  6.39209000e+03   8.77898310e-01]
 [  6.39213000e+03   8.77165350e-01]
 [  6.39216000e+03   8.85230030e-01]
 [  6.39220000e+03   9.09481760e-01]
 [  6.39224000e+03   9.30568740e-01]
 [  6.39228000e+03   9.57822830e-01]
 [  6.39232000e+03   9.80568050e-01]
 [  6.39236000e+03   9.96237970e-01]
 [  6.39239000e+03   9.94588280e-01]
 [  6.39243000e+03   9.84826900e-01]
 [  6.39247000e+03   9.60111460e-01]
 [  6.39251000e+03   9.28647670e-01]]

这只是印刷与取得结果的表述之间的区别。

>>> result = numpy.genfromtxt( testfile , delimiter=[8,24], dtype = float)
>>> repr(result)
 array([[  6.39201000e+03,   9.02861630e-01],
       [  6.39205000e+03,   8.87317780e-01],
       [  6.39209000e+03,   8.77898310e-01],
       [  6.39213000e+03,   8.77165350e-01],
       [  6.39216000e+03,
  8.85230030e-01],
       [  6.39220000e+03,   9.09481760e-01],
       [  6.39224000e+03,   9.30568740e-01],
       [  6.39228000e+03,   9.57822830e-01],
       [  6.39232000e+03,   9.80568050e-01],

[  6.39236000e+03,   9.96237970e-01],
       [  6.39239000e+03,   9.94588280e-01],
       [  6.39243000e+03,   9.84826900e-01],
       [  6.39247000e+03,   9.60111460e-01],
       [  6.39251000e+03,   9.2864
7670e-01]]) 

>>> str(result)
 [[  6.39201000e+03   9.02861630e-01]
 [  6.39205000e+03   8.87317780e-01]
 [  6.39209000e+03   8.77898310e-01]
 [  6.39213000e+03   8.77165350e-01]
 [  6.39216000e+03   8.85230030e-01]
 [  6.39220000e+03
 9.09481760e-01]
 [  6.39224000e+03   9.30568740e-01]
 [  6.39228000e+03   9.57822830e-01]
 [  6.39232000e+03   9.80568050e-01]
 [  6.39236000e+03   9.96237970e-01]
 [  6.39239000e+03   9.94588280e-01]
 [
 6.39243000e+03   9.84826900e-01]
 [  6.39247000e+03   9.60111460e-01]
 [  6.39251000e+03   9.28647670e-01]] 

通知说,str本是怎样的,但pr是怎样的?





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签