'空切片的意思'警告

时间:2017-04-12 03:25:23

标签: python-2.7 numpy warnings

考虑以下python文件(数据文件在最后)

#!/usr/bin/python

import pandas as pd
import numpy as np
from sklearn.preprocessing import LabelEncoder

feature_dict = {i:label for i,label in zip(
                range(36),
                  (
                'd(0)','d(1)','d(2)','d(3)','d(4)','d(5)','d(6)','d(7)','d(8)','d(9)','d(10)','d(11)','d(12)','d(13)','d(14)','d(15)','d(16)','d(17)','d(18)','d(19)','d(20)','d(21)','d(22)','d(23)','d(24)','d(25)','d(26)','d(27)','d(28)','d(29)','d(30)','d(31)','d(32)','d(33)','d(34)','d(35)',
                ))}

df = pd.io.parsers.read_csv(
    filepath_or_buffer='./lda-teste',
    header=None,
    sep=' ',
    )

df.columns = [l for i,l in sorted(feature_dict.items())] + ['grupo']
df.dropna(how="all", inplace=True) 

X = df[[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35]].values
y = df['grupo'].values

enc = LabelEncoder()
label_encoder = enc.fit(y)
y = label_encoder.transform(y) + 1

label_dict = {1: 'Cal_Tal', 2: 'MCal_Tal'}


mean_vectors = []
for cl in range(1,4):
    mean_vectors.append(np.mean(X[y==cl], axis=0))
    print('Mean Vector group %s: %s\n' %(cl, mean_vectors[cl-1]))

当我运行代码时,我收到警告

/usr/lib/python2.7/dist-packages/numpy/core/_methods.py:59: RuntimeWarning: Mean of empty slice.
  warnings.warn("Mean of empty slice.", RuntimeWarning)
Mean Vector group 3: [ nan  nan  nan  nan  nan  nan  nan  nan  nan  nan  nan  nan  nan  nan  nan
  nan  nan  nan  nan  nan  nan  nan  nan  nan  nan  nan  nan  nan  nan  nan
  nan  nan  nan  nan  nan  nan]

我试图在互联网上找到关于此类警告的一些信息,但我找到的所有信息都无助于解决我的问题,也无法帮助我理解问题的原因。

这很奇怪,因为对于第1组和第2组,平均值是可以的,但为什么不为第3组?

数据文件

112.00200 103.98450 99.66400 102.39600 108.25600 117.09400 129.68000 148.19400 166.95150 194.50150 188.32650 152.80250 129.92800 116.77050 108.25600 101.46150 98.37980 98.07565 99.00255 101.02800 109.61500 123.41600 136.94150 149.74300 160.19700 167.08400 174.68400 167.30200 163.59400 158.63000 149.90300 143.34250 136.29750 130.18050 124.48100 119.76850 Cal_Tal
134.00200 128.97850 127.17300 132.41200 138.47400 148.01150 157.46400 183.47350 231.16750 280.04000 233.94750 193.59800 165.77500 153.64650 141.93300 134.14550 132.08500 131.93350 133.00200 140.65050 153.27250 168.25850 182.39250 197.75550 209.68400 224.74350 243.15700 256.01950 249.24000 226.36600 205.83750 188.08850 174.58200 161.49450 148.83050 140.15850 Cal_Tal
96.50260 95.43845 93.81080 95.19960 104.67250 117.42000 131.04600 156.90450 188.32650 222.02800 188.32650 155.96450 138.24250 127.72250 119.91250 114.92150 111.02650 111.22450 113.50200 116.81400 125.42150 137.30750 150.50900 161.13700 170.74400 177.32550 186.36250 192.00650 193.42400 186.63600 173.83700 158.63900 141.93300 123.41600 109.61500 100.53530 Cal_Tal
174.00150 187.83350 198.34000 208.07000 222.85200 234.88950 242.18350 252.76250 268.25050 277.51450 280.72200 282.66650 266.11900 240.96750 215.42350 188.84650 164.03800 147.22600 139.00200 134.56900 134.43550 137.74250 143.72350 158.63900 182.33250 216.53700 283.85000 320.00100 248.34000 205.00450 184.13100 169.59100 164.72100 159.26250 159.12550 163.50400 Cal_Tal
156.00150 146.73350 141.09900 157.03000 173.17350 187.06250 218.86300 255.92400 339.66350 467.00500 342.70550 268.26850 228.29150 201.21450 179.57450 163.72700 155.96450 158.89900 165.00150 176.16100 197.86950 224.69350 255.88350 286.10000 318.09000 356.99300 401.56050 431.51450 397.36350 358.10450 321.43850 286.10000 251.65700 217.06300 175.74250 164.98100 Cal_Tal
125.00200 135.55300 146.95050 169.55650 200.18750 228.99650 252.47750 265.57950 268.04950 275.11800 269.54600 262.07750 249.74600 227.14000 202.62100 177.61900 160.53500 152.32400 144.00150 138.19050 137.12550 141.84150 153.97050 164.65850 178.55200 204.49550 246.19700 327.50200 253.43800 197.40000 164.66000 144.04650 131.68700 125.21400 121.32000 120.26100 MCal_Tal
153.00150 154.29350 157.37400 155.23200 162.16150 172.85050 188.59900 204.49550 233.04650 266.00400 233.04650 204.83500 186.61450 173.17350 169.97200 169.55650 171.29950 171.06400 175.00150 177.63900 185.22550 191.51100 193.78600 198.33650 209.68400 216.54000 231.25950 246.50200 252.55000 237.13150 223.32700 208.32050 186.35850 167.32450 164.50800 162.02700 Cal_Tal
185.00150 186.84900 188.85600 190.64450 200.18750 208.64100 220.22950 236.95750 262.47450 302.00750 271.77450 241.05700 222.46100 210.49550 202.24000 187.04700 187.91700 185.86500 189.50150 195.39400 202.31300 207.63550 211.19950 217.22000 227.54450 241.23750 271.68500 282.04450 268.82800 247.21150 234.98700 223.29900 210.43100 200.93900 194.70850 191.45400 MCal_Tal
170.00150 170.07900 167.19900 167.32450 176.75700 184.56700 198.27500 217.48000 243.15700 280.50100 253.43800 220.64100 190.46650 175.66800 154.73550 152.99800 146.48200 131.44100 130.50200 146.73350 151.86450 165.09200 171.76400 180.98350 207.20250 205.17900 238.89250 238.50800 225.18650 210.04500 208.07000 204.41400 201.21250 191.94500 183.47450 175.17650 MCal_Tal
473.50050 436.08600 396.38000 386.43650 380.46400 390.77150 409.25650 431.49400 483.76100 251.00100 215.78350 688.52650 53.77090 32.42610 23.13620 19.47925 18.20630 17.18995 17.01470 16.20165 17.74600 18.61280 20.93790 26.63365 33.61930 463.44650 688.45100 60.50415 118.78250 249.60100 326.58650 395.00600 483.72700 526.22550 530.04400 511.71150 MCal_Tal
208.00100 232.06150 253.23200 275.29800 283.15900 320.86200 351.45550 378.35300 402.71950 457.50200 436.08600 387.06900 351.45550 321.56650 299.54450 269.03400 240.58750 219.40500 204.50100 202.63400 199.62200 205.83750 224.26100 244.55150 277.78150 322.05100 388.41050 512.50050 425.89050 338.96650 283.36050 252.36150 231.04450 207.63550 206.88300 196.06000 Cal_Tal
200.00100 198.52100 204.66250 213.89950 215.80750 231.42850 266.11900 283.60600 343.69000 411.50050 426.06400 340.54800 286.95700 251.27450 224.64250 214.83100 206.41350 205.09650 211.50100 226.96400 245.15900 262.77100 288.53350 322.97500 349.47500 371.09150 379.78000 360.51150 336.98500 327.26200 332.41650 319.71500 286.74200 258.30800 239.30650 216.27650 MCal_Tal
167.00150 162.02750 159.12550 157.46400 165.74500 174.58200 185.24850 202.61450 234.12050 280.50350 270.79050 231.57500 204.97100 190.20250 175.99150 169.55650 164.03800 161.04300 161.50150 168.10900 180.31250 193.74300 209.02250 222.85200 233.87000 248.32450 254.82950 256.06250 248.25450 235.34000 224.08150 216.89700 210.04950 195.54300 178.90350 170.57150 Cal_Tal

0 个答案:

没有答案