简体   繁体   English

填充二维数组以计算两个线性空间的函数

[英]Populating a 2D array to calculate a function of two linspaces

I have this set of equations I want to perform:我有这组要执行的方程:

x = np.linspace(0, 2, 3)
y = np.linspace(x, x+2, 3)

I then want to populate the 2D array with a calculation that does:然后我想用一个计算来填充二维数组:

a = 2*x + y

So for example, given an array:例如,给定一个数组:

x = [0, 1, 2]

Then, the array y is:那么,数组y是:

y = [[0, 1, 2],
     [1, 2, 3],
     [2, 3, 4]]

When I perform the operation a = 2*x + y I should get the array:当我执行操作a = 2*x + y我应该得到数组:

a = [[0, 1, 2],
     [3, 4, 5],
     [6, 7, 8]]

How do I do this, keeping in mind I want to perform this operation quickly for array of size up to 10000x10000 (or larger)?我该怎么做,记住我想对大小高达10000x10000 (或更大)的数组快速执行此操作?

Or do your code adding two T s:或者你的代码添加两个T s:

print((2*x+y.T).T)

Output:输出:

[[0 1 2]
 [3 4 5]
 [6 7 8]]

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM