2014-09-04 32 views
0

晚安好,我有一个问题,即时试图连接字符串到一个数组我有一个.txt中,在3个gruoups划分“.I 1" ,” 2" .I “.I 3”我的代码生成一个“.I n”总数的数组,在这种情况下是一个3的数组,我的目标是将“.I x”之后的所有行存储在数组的x位置例如....“.I 1" 阵列[1],” .I 2" 在阵列[2]等级联序列插入numpy的阵列中蟒

我的代码只是保存的最后一行的下一个“.I”之前,而不是保存所有的线路,我知道这将发生,但问题是,我不知道如何连接或推或追加线到阵列的相同位置

txt文件cran.all.txt

.I 1 
.T 
experimental investigation of the aerodynamics of a 
wing in a slipstream . 
.A 
brenckman,m. 
.B 
j. ae. scs. 25, 1958, 324. 
.W 
experimental investigation of the aerodynamics of a 
wing in a slipstream . 
    an experimental study of a wing in a propeller slipstream was 
made in order to determine the spanwise distribution of the lift 
increase due to slipstream at different angles of attack of the wing 
and at different free stream to slipstream velocity ratios . the 
results were intended in part as an evaluation basis for different 
theoretical treatments of this problem . 
    the comparative span loading curves, together with 
supporting evidence, showed that a substantial part of the lift increment 
produced by the slipstream was due to a /destalling/ or 
boundary-layer-control effect . the integrated remaining lift 
increment, after subtracting this destalling lift, was found to agree 
well with a potential flow theory . 
    an empirical evaluation of the destalling effects was made for 
the specific configuration of the experiment . 


.I 2 
.T 
simple shear flow past a flat plate in an incompressible fluid of small 
viscosity . 
.A 
ting-yili 
.B 
department of aeronautical engineering, rensselaer polytechnic 
institute 
troy, n.y. 
.W 
simple shear flow past a flat plate in an incompressible fluid of small 
viscosity . 
in the study of high-speed viscous flow past a two-dimensional body it 
is usually necessary to consider a curved shock wave emitting from the 
nose or leading edge of the body . consequently, there exists an 
inviscid rotational flow region between the shock wave and the boundary 
layer . such a situation arises, for instance, in the study of the 
hypersonic viscous flow past a flat plate . the situation is somewhat 
different from prandtl's classical boundary-layer problem . in prandtl's 
original problem the inviscid free stream outside the boundary layer is 
irrotational while in a hypersonic boundary-layer problem the inviscid 
free stream must be considered as rotational . the possible effects of 
vorticity have been recently discussed by ferri and libby . in the 
present paper, the simple shear flow past a flat plate in a fluid of small 
viscosity is investigated . it can be shown that this problem can again 
be treated by the boundary-layer approximation, the only novel feature 
being that the free stream has a constant vorticity . the discussion 
here is restricted to two-dimensional incompressible steady flow . 


.I 3 
.T 
the boundary layer in simple shear flow past a flat plate . 
.A 
m. b. glauert 
.B 
department of mathematics, university of manchester, manchester, 
england 
.W 
the boundary layer in simple shear flow past a flat plate . 
the boundary-layer equations are presented for steady 
incompressible flow with no pressure gradient . 

Python代码

import re 
import numpy as np 

def total_archivos() : 
    hand = open("cran.all.txt") 
    total= 0 
    for line in hand: 
     line = line.strip() 
     if ".I" in line: 
      total=total+1 
    return total 

def escribir() : 
    hand = open("cran.all.txt") 
    total= 0 
    for line in hand: 
     line = line.strip() 
     if ".I" in line: 
      total=total+1 
     else: 
      textos[total-1]=np.array(line) 



cuenta=total_archivos() 
textos = np.array(range(cuenta), dtype='|S1000') 
escribir() 
print cuenta 
print textos[0] 
print textos[1] 
print textos[2] 

结果

1400 
the specific configuration of the experiment . 
here is restricted to two-dimensional incompressible steady flow . 
incompressible flow with no pressure gradient . 

请注意,这只是从每个“一最后一行X”我要存储在同一个阵列位置的所有行。在先进的感谢

很多关于你的帮助。

回答

0

我发现了一个简单的解决方案,而不是阵列中的令人担忧串连,我创建简单称为“文档”我用此变量以连接线,然后当时间变量它们所有连接我只保存在我想要的数组位置的变量,然后我清理变量这是如何我的代码结束了

import re 
import numpy as np 



def total_archivos() : 
    hand = open("cran.all.txt") 
    total= 0 
    for line in hand: 
     line = line.strip() 
     if ".I" in line: 
      total=total+1 
    return total 

def escribir(doc) : 
    hand = open("cran.all.txt") 
    total= 0 
    for line in hand: 
     line = line.strip() 
     if ".I" in line: 
      doc = "" 
      total=total+1 
     else: 
      doc = doc + line 
      textos[total-1]=doc 



doc = "" 
cuenta=total_archivos() 
textos = np.array(range(cuenta), dtype='|S2000') 
np.array(textos).tolist() 
escribir(doc) 
print cuenta 
print textos[1330]