python3.6 numpy 1.13.1 数组打印不全 输出是省略号的问题

numpy 数组用print 默认输出最前面3行和最后3行:

import numpy as np

#np.set_printoptions(threshold=np.nan)    #设置打印数量的阈值

dataFileName = 'datingSets.txt'

dataFile = open(dataFileName, 'r+')
dataSet = dataFile.readlines() # 读取文件的全部内容
numberOfLines = len(dataSet) # 获得数据集的行数
returnMat = np.zeros((numberOfLines, 3)) # 创建一个初始值为0,大小为 numberOfLines x 3 的数组
classLabelVector = [] # 用于保存没个数据的类别标签

index = 0
for line in dataSet:  # 处理每一行数据
    line = line.strip()  # 去掉行首尾的空白字符,(包括'\n', '\r',  '\t',  ' ')
    listFromLine = line.split()  # 分割每行数据,保存到一个列表中
    returnMat[index, :] = listFromLine[0:3]  # 将列表中的特征保存到reurnMat中
    classLabelVector.append(int(listFromLine[-1]))  # 保存分类标签
    index += 1

print(returnMat)

输出:

E:\Python36\python.exe E:/PycharmProjs/test3.py
[[  6.96500000e+03   8.13923003e+01   1.56336061e+00]
 [  4.88000000e+03   8.82246865e+01   4.69936230e-01]
 [  3.59600000e+03   2.47930417e+00   1.77832451e+00]
 ..., 
 [  4.28700000e+03   5.76863064e+01   1.58363997e+00]
 [  9.15000000e+03   9.40221958e+01   8.96529800e-01]
 [  5.04600000e+03   3.03901542e+01   7.32563750e-01]]

Process finished with exit code 0

添加一句:np.set_printoptions(threshold=np.nan) #设置打印数量的阈值

结果都输出出来了,开始的时候我还以为是print的限制呢。

转载于:https://my.oschina.net/michaelshu/blog/1536724

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值