以下循环的每次迭代都生成一个维数为50x1的向量 我喜欢将循环中的所有向量集中存储在一个数据结构中。在
def get_y_hat(y_bar, x_train, theta_Ridge_Matrix):
print theta_Ridge_Matrix.shape
print theta_Ridge_Matrix.shape[0]
for i in range(theta_Ridge_Matrix.shape[0]):
yH = np.dot(x_train, theta_Ridge_Matrix[i].T)
print yH
我应该使用哪种数据结构?我是Python新手,但基于我在线研究的内容,有两个选项:numpy数组和列表列表
我需要在这个方法之外访问50个元素的每个向量。我会存储200到500个向量。在
有人能给我这种数据结构的示例代码吗
谢谢
我认为将循环中的数据存储在} (它是在numpy数组之上构建的)应该是一个有效的解决方案,允许您进一步将数据作为一个整体或单个向量进行处理。在
dict
中,然后将其转换为^{例如:
可以将单个向量作为属性访问,也可以通过以下键访问:
^{pr2}$或者进一步分析整个数据:
或者使用
matplotlib
查看您的数据我建议使用numpy来安装它
在此站点的windows上:
http://sourceforge.net/projects/numpy/files/NumPy/
一些你如何使用它的例子。在
我们将创建一个数组,命名为mat
^{pr2}$数组使用动词“T”进行转置
任何数组的形状都可以通过使用\verb“整形”方法进行更改
我们可以使用\动词“shape”属性更改变量的形状。在
相关问题 更多 >
编程相关推荐