遍历n行数组,然后遍历n行,依此类推

时间:2020-08-21 21:22:47

标签: python

我有看起来像这样的C数组

array([23, 23, 23, ..., 68, 34, 42])

其索引存储在另一个看起来像

的数组D中
array([[23989, 10991, 81533, ..., 75050, 13817, 47678],
       [54864, 54830, 89396, ..., 22709, 14556, 62298],
       [ 2936, 28729,  4404, ..., 21431, 81187, 49178],
       ...,
       [30737, 12974, 41031, ..., 43003, 61132, 33385],
       [64713, 53207, 49529, ..., 72596, 76406, 15207],
       [29503, 71648, 27210, ..., 31298, 47102, 13024]])

每行包含大约30个C随机索引。 我想做的是对C的300个随机绘制的索引使用前10行,然后对接下来的300个随机绘制的索引使用接下来的10行,等等。

我可以使用代码从C中随机抽取1000组30个观测值

means_size_30 = C[D].mean(axis=1)
plt.hist(means_size_30)
plt.axvline(np.mean(C))

但是我如何获得10行,然后获得接下来的10行以获得所需的结果? 添加for循环只会让我获得单个行的平均值(有30个观察值),我想要的是前10行的平均值,然后是后10行的平均值,依此类推。

for i in range(0,1000,10):
    means_size_300 = C[D[i:i+10,:]].mean(axis=1)
    print(C[D[i:i+10,:]])
    print(means_size_300)
plt.hist(means_size_300)
plt.axvline(np.mean(C))

1 个答案:

答案 0 :(得分:0)

使用循环:

public static relationMappings = {
    attributes: {
      relation: Model.ManyToManyRelation,
      modelClass: 'Attribute',
      join: {
        from: 'products.id',
        through: {
          from: 'products_attributes.products_id',
          to: 'products_attributes.attributes_id',
          extra: {
            value: 'value',
            attributes_dictionaries_id: 'attributes_dictionaries_id',
          },
        },
        to: 'attributes.id',
      },
    },
    variants: {
      relation: Model.ManyToManyRelation,
      modelClass: 'Variant',
      join: {
        from: 'products.id',
        through: {
          from: 'products_variants.products_id',
          to: 'products_variants.variants_id',
        },
        extra: {
          value: 'value',
          attributes_dictionaries_id: 'attributes_dictionaries_id',
        },
        to: 'variants.id',
      },
    },
}