我试图遵循documentation中np.linalg.svd
中提供的一些示例代码,以比较TDM矩阵上的SVD之后的术语和文档相似性。下面是我得到了什么:无法将形状(1285)中的输入数组广播成形(1285,5344)
results_t = np.linalg.svd(tdm_t)
results_t[1].shape
产生
(1285,)
而且
results_t[2].shape
(5334, 5334)
所以后来试图播放这些结果来创建每个经典的SVD投影方式真正S
矩阵,我得到了:
S = np.zeros((results_t[0].shape[0], results_t[2].shape[0]), dtype = float)
S[:results_t[2].shape[0], :results_t[2].shape[0]] = results_t[1]
最后一行产生错误:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-329-16e79bc97c4b> in <module>()
----> 1 S[:results_t[2].shape[0], :results_t[2].shape[0]] = results_t[1]
ValueError: could not broadcast input array from shape (1285) into shape (1285,5334)
我在做什么错在这里?
尝试'results_t [1] [:,无]' – Joel
如果下面的答案没有帮助,您能否明确说明错误行将被执行? – Joel
你想分配一个块还是对角线? – hpaulj