Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/354.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在python中将序列连接到numpy数组中_Python_Arrays_Numpy_Append_Concatenation - Fatal编程技术网

在python中将序列连接到numpy数组中

在python中将序列连接到numpy数组中,python,arrays,numpy,append,concatenation,Python,Arrays,Numpy,Append,Concatenation,晚安,伙计们,我有一个问题,我正在尝试将字符串连接到一个数组中,我有一个.txt,它被分成3个组“.i 1”“.i 2”“.i 3”“我的代码生成一个总数为“.i n”的数组,在本例中是一个3的数组,我的目标是在数组示例的x位置存储“.i x”之后的所有行。。。。数组[1]中的“.i1”,数组[2]中的“.i2”等 我的代码只是在下一行之前保存最后一行“.I”而不是保存所有的行,我知道这会发生,但问题是我不知道如何将行连接、推送或附加到数组的同一位置 TXT文件cran.all.TXT .I 1

晚安,伙计们,我有一个问题,我正在尝试将字符串连接到一个数组中,我有一个.txt,它被分成3个组“.i 1”“.i 2”“.i 3”“我的代码生成一个总数为“.i n”的数组,在本例中是一个3的数组,我的目标是在数组示例的x位置存储“.i x”之后的所有行。。。。数组[1]中的“.i1”,数组[2]中的“.i2”等

我的代码只是在下一行之前保存最后一行“.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 .
请注意,这只是每个“I.x”的最后一行,我希望将所有行存储在同一数组位置


在advanced中,非常感谢您的帮助。

我建议使用和来处理您线路的结尾和开头!这样你就有了一个更具pythonic风格的代码和更少的错误

我找到了一个更简单的解决方案,不用担心数组中的串联,我创建了一个名为“doc”的简单时态变量,我使用这个变量来串联行,然后当它们全部串联在一起时,我只需将变量保存在我想要的数组位置,然后清理变量,这就是我的代码的结尾

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]

Thx很多,但我有几个问题,你会如何使用它?它还给我布尔值,你对它的实现有什么想法吗?