简体   繁体   English

关于在python中串联两个向量

[英]About concatenating two vectors in python

I have a vector y of size 4 x 1 , and another vector y2 of size 1 x 4 , I need to concatenate the vectors y and real and imaginary parts of y2 . 我有一个向量y ,大小为4 x 1 ,另一个向量y2 ,大小为1 x 4 ,我需要将向量y以及y2实部和虚部连接起来。

The problem is that when I reshape the vector y2 into vector 4 x 1 , and then concatenate it with vector y , it gives me an error of 'all the input array dimensions except for the concatenation axis must match exactly' . 问题是,当我将向量y2为向量4 x 1 ,然后将其与向量y串联时,这给我一个错误: 'all the input array dimensions except for the concatenation axis must match exactly'

Here is the code I made, So Y3 is expected to be a vector of size 12 x 1 , but the last command gives an error: 这是我编写的代码,因此Y3应该是大小为12 x 1的向量,但是最后一条命令给出了错误:

import numpy as np

h = np.random.randn(4, 4) + 1j * np.random.randn(4, 4)
x = np.array([[1 + 1j], [0 + 0j], [0 + 0j], [0 + 0j]])
y = h.dot(x)
n = 3
y2 = np.zeros((1, 4), dtype=np.complex)
for ii in range(n):
    y2[: , ii] = np.linalg.pinv(h[: , ii].reshape(-1,1)).dot(x)
y_con = np.concatenate((np.real(y2),np.imag(y2)))
y_m = np.absolute(y)
y_con2 = y_con.reshape(8,1)
Y3 = np.concatenate((y_con2, y_m))
Y3  = np.concatenate([y_con.reshape(-1,1), y_m])

y_m为4 X 1因此将y_con重塑为n X 1以便逐行连接

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

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