简体   繁体   English

Python:如何在具有 N 列的矩阵中转换数组,这些数组是重复 N 次的相同数组?

[英]Python: how can I transform an array in a matrix with N columns, that are the same array repeated N times?

I have an array and I have to create a matrix with N columns (N is a parameter that can be changed).我有一个数组,我必须创建一个包含 N 列的矩阵(N 是一个可以更改的参数)。 So we have to copy this array N times.所以我们必须复制这个数组 N 次。

If I understand correctly your input would be for example:如果我理解正确,您的输入将是例如:

a = [12, 8, 9]
n = 2

And the output would be:输出将是:

b = [[12, 12],
     [ 8,  8],
     [ 9,  9]]

Here is how you could do that:您可以这样做:

b = [[i]*n for i in a]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将一系列形状为 (n,1) 的数字作为 n 个唯一数字的数组重复 4 次,形状为 (n,1) - How to repeat a series of numbers with shape (n,1) as an array of n unique numbers repeated by 4 times with a shape of (n,1) 将数组附加到不同的数组 N 次(python) - Appending Array into different array N times (python) 如何将大小为 N 的 numpy 列数组乘以 python 中大小为 N 的行数组以获得 NXN 矩阵? - how to multiply a numpy column array of size N to row array of size N in python to get N X N matrix? 如何使用 c function 在 numpy 数组上进行计算 - How to do computation with a c function on a numpy array of a non square matrix of size `n` times `m` (n≠m) 如何生成具有N行和N列的数组,每个元素是2行单列零矩阵? - How do I generate an array with N rows and N columns with each element being a 2 row single column zero matrix? 如何从矩阵的所有列中减去相同的数组? - How can I subtract the same array from all the columns of a matrix? 如何制作一个 10 的下三角阵列,但在对角线上重复 n 次? - How to make a lower triangle array of 10 but repeated across a diagonal n times? 在 Python 中将一个数组与自身网格化 n 次 - Meshgriding an array with itself n times, in Python 使用Python从数组中打印N次 - Print Number N times from array with Python Python:连接(或克隆)一个 numpy 数组 N 次 - Python: Concatenate (or clone) a numpy array N times
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM