numpy Python创建两个三变量列表来镜像

yzckvree  于 2023-05-13  发布在  Python
关注(0)|答案(1)|浏览(194)

我在收集数据:

ads.mode = ADS.Mode.SINGLE

chan = AnalogIn(ads, ADS.P0, ADS.P1)
 
buffer = []

buffer.append(chan.value) # I'm collecting chan values in the buffer

当chan的数量达到144值时,我想创建.tiff大小的图像,其中2P = 122Q = 12(12*12给出144)以及后续的chan值 按图像中箭头所示的顺序写入:

对于在python中使用数组的人来说,这个问题看起来很简单。我将非常感谢你的帮助。

h4cxqtbf

h4cxqtbf1#

我想你是说这个。

import numpy as np

# Generate 144 linearly increasing samples to test
samples = list(range(144))

# Make into Numpy array and reshape to (12,12)
a = np.array(samples).reshape((12,12))

# Reverse alternate rows
for r in range(1,12,2):
   a[r] = a[r][::-1]

结果

array([[  0,   1,   2,   3,   4,   5,   6,   7,   8,   9,  10,  11],
   [ 23,  22,  21,  20,  19,  18,  17,  16,  15,  14,  13,  12],
   [ 24,  25,  26,  27,  28,  29,  30,  31,  32,  33,  34,  35],
   [ 47,  46,  45,  44,  43,  42,  41,  40,  39,  38,  37,  36],
   [ 48,  49,  50,  51,  52,  53,  54,  55,  56,  57,  58,  59],
   [ 71,  70,  69,  68,  67,  66,  65,  64,  63,  62,  61,  60],
   [ 72,  73,  74,  75,  76,  77,  78,  79,  80,  81,  82,  83],
   [ 95,  94,  93,  92,  91,  90,  89,  88,  87,  86,  85,  84],
   [ 96,  97,  98,  99, 100, 101, 102, 103, 104, 105, 106, 107],
   [119, 118, 117, 116, 115, 114, 113, 112, 111, 110, 109, 108],
   [120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131],
   [143, 142, 141, 140, 139, 138, 137, 136, 135, 134, 133, 132]])

相关问题