a=zeros(3,10000);a(:,1:20) Columns 1 through 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 16 through 20 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
然而在Numpy
import numpy as npset_printoptions(threshold=nan)a=np.zeros((3,10000))print a[:,0:20][[ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]]
如你所见,numpy打印第一行,然后是第二行,然后是第三行.我希望它保持列结构而不是行结构
非常感谢你
PS:例如,一种解决方案就是
print a[:,0:20].T[[ 0. 0. 0.] [ 0. 0. 0.] [ 0. 0. 0.] [ 0. 0. 0.] [ 0. 0. 0.] [ 0. 0. 0.] [ 0. 0. 0.] [ 0. 0. 0.] [ 0. 0. 0.] [ 0. 0. 0.] [ 0. 0. 0.] [ 0. 0. 0.] [ 0. 0. 0.] [ 0. 0. 0.] [ 0. 0. 0.] [ 0. 0. 0.] [ 0. 0. 0.] [ 0. 0. 0.] [ 0. 0. 0.] [ 0. 0. 0.]]
但是,屏幕上会消耗比预期更多的空间.如果numpy有这个选项会很棒
解决方法 这会给你想要的吗?>>> for item in a[:,0:20].T: print '\t'.join(map(str,item.toList()))
或这个?
>>> for item in a[:,0:20]: print '\t'.join(map(str,item.toList()))总结
以上是内存溢出为你收集整理的python – 像Matlab一样在numpy中打印子数组全部内容,希望文章能够帮你解决python – 像Matlab一样在numpy中打印子数组所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)