小编Uni*_*ron的帖子

传入标志作为re.compile的参数

我想基于类似于下面的逻辑将某些标志传递给re.compile函数.我想知道是否可以这样做.

  flags = ""

  if multiline:
    flags = 're.M'

  if dotall:
    flags = flags + '|re.S'

  if verbose:
    flags = flags + '|re.X'

  if ignorecase:
    flags = flags + '|re.I'

  if uni_code:
    flags = flags + '|re.U'

  regex = re.compile(r'Test Pattern', flags)
Run Code Online (Sandbox Code Playgroud)

python regex

11
推荐指数
1
解决办法
6225
查看次数

以块状形式组合Numpy阵列

我有三个Numpy矩阵

a = np.matrix('1 2; 3 4')

b = np.matrix('5 6 7; 8 9 10')

c = np.matrix('1 2 3; 4 5 6; 7 8 9')

我想制作以下块矩阵:

M = [a b ; 0 c],

其中0代表具有相关尺寸的零矩阵.

python numpy matrix

5
推荐指数
1
解决办法
4059
查看次数

标签 统计

python ×2

matrix ×1

numpy ×1

regex ×1