IndexError: only integers, slices (:
), ellipsis (...
), numpy.newaxis (None
) and integer or boolean arrays are valid indices とエラーが出ました。
import numpy as np import pandas as pd import scipy as sp import pickle from scipy import fft from time import localtime, strftime import matplotlib.pyplot as plt from skimage.morphology import disk,remove_small_objects from skimage.filter import rank from skimage.util import img_as_ubyte import wave folder = 'mlsp_contest_dataset/' essential_folder = folder+'essential_data/' supplemental_folder = folder+'supplemental_data/' spectro_folder =folder+'my_spectro/' single_spectro_folder =folder+'my_spectro_single/' dp_folder = folder+'DP/' # Each audio file has a unique recording identifier ("rec_id"), ranging from 0 to 644. # The file rec_id2filename.txt indicates which wav file is associated with each rec_id. rec2f = pd.read_csv(essential_folder + 'rec_id2filename.txt', sep = ',') # There are 19 bird species in the dataset. species_list.txt gives each a number from 0 to 18. species = pd.read_csv(essential_folder + 'species_list.txt', sep = ',') num_species = 19 # The dataset is split into training and test sets. # CVfolds_2.txt gives the fold for each rec_id. 0 is the training set, and 1 is the test set. cv = pd.read_csv(essential_folder + 'CVfolds_2.txt', sep = ',') # This is your main label training data. For each rec_id, a set of species is listed. The format is: # rec_id,[labels] raw = pd.read_csv(essential_folder + 'rec_labels_test_hidden.txt', sep = ';') label = np.zeros(len(raw)*num_species) label = label.reshape([len(raw),num_species]) for i in range(len(raw)): line = raw.iloc[i] labels = line[0].split(',') labels.pop(0) # rec_id == i for c in labels: if(c != '?'): print(label) label[i,c] = 1
と書いてあるコードを実行したところ、
label[i,c] = 1
のところで上記のエラーが出ました。
試しに、print(label)でlabelの中身を見て見たのですが、
warn(skimage_deprecation('The `skimage.filter` module has been renamed ' [[ 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.]]
と出力されました。
エラー文は、配列の要素はintegers, slices (:
), ellipsis (...
), numpy.newaxis (None
) and integer or boolean は使えない、という意味だと思っていますが、配列の要素に数字(int)を入れたことはたくさんあるので、なぜここでエラーが出るのかわかりません。
どのように直せば良いのでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。