質問するログイン新規登録

質問編集履歴

3

一部パラメータをダミーに

2026/07/05 15:15

投稿

Uta_fai
Uta_fai

スコア18

title CHANGED
File without changes
body CHANGED
@@ -1,113 +1,114 @@
1
- ### 前提・実現したいこと
2
- numpyのlistをnp.save()によって保存をしたい。
3
-
4
- ### 発生している問題・エラーメッセージ
5
-
6
- ---------------------------------------------------------------------------
7
- ValueError Traceback (most recent call last)
8
- <ipython-input-1-1775b596e8ba> in <module>()
9
- 60
10
- 61 filename = 'x.npy'
11
- ---> 62 np.save(filename, audio)
12
- 63 filename_2='y.npy'
13
- 64 np.save(filename_2,label)
14
-
15
- ~\Anaconda3\lib\site-packages\numpy\lib\npyio.py in save(file, arr, allow_pickle, fix_imports)
16
- 517
17
- 518 try:
18
- --> 519 arr = np.asanyarray(arr)
19
- 520 format.write_array(fid, arr, allow_pickle=allow_pickle,
20
- 521 pickle_kwargs=pickle_kwargs)
21
-
22
- ~\Anaconda3\lib\site-packages\numpy\core\numeric.py in asanyarray(a, dtype, order)
23
- 551
24
- 552 """
25
- --> 553 return array(a, dtype, copy=False, order=order, subok=True)
26
- 554
27
- 555
28
-
29
- ValueError: could not broadcast input array from shape (20,883) into shape (20)
30
- #コード
31
-
32
- ```
33
-
34
- import librosa
35
- import os
36
- import numpy as np
37
-
38
- audio=[]
39
- label=[]
40
- name=[]
41
-
42
- path='./'
43
- angry=os.path.join(path,'angry')
44
- angryl = os.listdir(angry)
45
- happy=os.path.join(path,'happy')
46
- happyl = os.listdir(happy)
47
- normal = os.path.join(path,'normal')
48
- normall= os.listdir(normal)
49
-
50
- max = 0
51
- print("start")
52
- for aud in angryl:
53
- apath = os.path.join(angry,aud)
54
- x,fs = librosa.load(apath,sr=44100)
55
- mfccs= librosa.feature.mfcc(x,sr=fs)
56
- #print (mfccs.shape)
57
- #print(type(mfccs))
58
- audio.append(mfccs)
59
- if(max<mfccs.shape[1]):
60
- max = mfccs.shape[1]
61
- la = 0
62
- label.append(la)
63
- name.append(aud)
64
- #print(type(audio))
65
-
66
- print("33%")
67
- for aud in normall:
68
- apath = os.path.join(normal,aud)
69
- x,fs = librosa.load(apath,sr=44100)
70
- mfccs= librosa.feature.mfcc(x,sr=fs)
71
- #print (mfccs.shape)
72
- #print(type(mfccs))
73
- audio.append(mfccs)
74
- if(max<mfccs.shape[1]):
75
- max = mfccs.shape[1]
76
- la = 1
77
- label.append(la)
78
- name.append(aud)
79
-
80
- print("66%")
81
- for aud in happyl:
82
- apath = os.path.join(happy,aud)
83
- x,fs = librosa.load(apath,sr=44100)
84
- mfccs= librosa.feature.mfcc(x,sr=fs)
85
- # print (mfccs.shape)
86
- #print(type(mfccs))
87
- audio.append(mfccs)
88
- if(max<mfccs.shape[1]):
89
- max = mfccs.shape[1]
90
- la = 2
91
- label.append(la)
92
- name.append(aud)
93
-
94
- filename = 'x.npy'
95
- np.save(filename, audio)
96
- filename_2='y.npy'
97
- np.save(filename_2,label)
98
- filename_3='fn.npy'
99
- np.save(filename_3,name)
100
-
101
- print(max)
102
- print("finish")
103
-
104
- ```Python
105
- ### 試したこと
106
-
107
- ファイルネームの拡張子を.npzに変えたりしました。
108
- audio はnp.darrayのlist 次元数は2です。
109
- label は整数のlist
110
- filename は元ファイルのパスを保存しているlistであることをtype()によって確認しました。
111
-
112
- ### 補足情報(FW/ツールのバージョンなど)
1
+ ### 前提・実現したいこと
2
+ numpyのlistをnp.save()によって保存をしたい。
3
+
4
+ ### 発生している問題・エラーメッセージ
5
+
6
+ ---------------------------------------------------------------------------
7
+ ValueError Traceback (most recent call last)
8
+ <ipython-input-1-1775b596e8ba> in <module>()
9
+ 60
10
+ 61 filename = 'x.npy'
11
+ ---> 62 np.save(filename, audio)
12
+ 63 filename_2='y.npy'
13
+ 64 np.save(filename_2,label)
14
+
15
+ ~\Anaconda3\lib\site-packages\numpy\lib\npyio.py in save(file, arr, allow_pickle, fix_imports)
16
+ 517
17
+ 518 try:
18
+ --> 519 arr = np.asanyarray(arr)
19
+ 520 format.write_array(fid, arr, allow_pickle=allow_pickle,
20
+ 521 pickle_kwargs=pickle_kwargs)
21
+
22
+ ~\Anaconda3\lib\site-packages\numpy\core\numeric.py in asanyarray(a, dtype, order)
23
+ 551
24
+ 552 """
25
+ --> 553 return array(a, dtype, copy=False, order=order, subok=True)
26
+ 554
27
+ 555
28
+
29
+ ValueError: could not broadcast input array from shape (20,883) into shape (20)
30
+ #コード
31
+
32
+ ```
33
+
34
+
35
+ import librosa
36
+ import os
37
+ import numpy as np
38
+
39
+ audio=[]
40
+ label=[]
41
+ name=[]
42
+
43
+ path='./'
44
+ X=os.path.join(path,'X')
45
+ Xl = os.listdir(X)
46
+ Y=os.path.join(path,'Y')
47
+ Yl = os.listdir(Y)
48
+ Z = os.path.join(path,'Z')
49
+ Zl= os.listdir(Z)
50
+
51
+ max = 0
52
+ print("start")
53
+ for aud in Xl:
54
+ apath = os.path.join(X,aud)
55
+ x,fs = librosa.load(apath,sr=44100)
56
+ mfccs= librosa.feature.mfcc(x,sr=fs)
57
+ #print (mfccs.shape)
58
+ #print(type(mfccs))
59
+ audio.append(mfccs)
60
+ if(max<mfccs.shape[1]):
61
+ max = mfccs.shape[1]
62
+ la = 0
63
+ label.append(la)
64
+ name.append(aud)
65
+ #print(type(audio))
66
+
67
+ print("33%")
68
+ for aud in Zl:
69
+ apath = os.path.join(Z,aud)
70
+ x,fs = librosa.load(apath,sr=44100)
71
+ mfccs= librosa.feature.mfcc(x,sr=fs)
72
+ #print (mfccs.shape)
73
+ #print(type(mfccs))
74
+ audio.append(mfccs)
75
+ if(max<mfccs.shape[1]):
76
+ max = mfccs.shape[1]
77
+ la = 1
78
+ label.append(la)
79
+ name.append(aud)
80
+
81
+ print("66%")
82
+ for aud in Yl:
83
+ apath = os.path.join(Y,aud)
84
+ x,fs = librosa.load(apath,sr=44100)
85
+ mfccs= librosa.feature.mfcc(x,sr=fs)
86
+ # print (mfccs.shape)
87
+ #print(type(mfccs))
88
+ audio.append(mfccs)
89
+ if(max<mfccs.shape[1]):
90
+ max = mfccs.shape[1]
91
+ la = 2
92
+ label.append(la)
93
+ name.append(aud)
94
+
95
+ filename = 'x.npy'
96
+ np.save(filename, audio)
97
+ filename_2='y.npy'
98
+ np.save(filename_2,label)
99
+ filename_3='fn.npy'
100
+ np.save(filename_3,name)
101
+
102
+ print(max)
103
+ print("finish")
104
+
105
+ ```Python
106
+ ### 試したこと
107
+
108
+ ファイルネームの拡張子を.npzに変えたりしました。
109
+ audio はnp.darrayのlist 次元数は2です。
110
+ label は整数のlist
111
+ filename は元ファイルのパスを保存しているlistであることをtype()によって確認しました。
112
+
113
+ ### 補足情報(FW/ツールのバージョンなど)
113
114
  自作で音声データセットを作ろうと試みています。librosaというライブラリを使い各音声データの特徴量(numpy.darray)とラベルとファイルネームをそれぞれ冒頭で定義したlistに保存し、np.save()によって保存を試みましたが、上記の様なエラーが出てしまい保存をすることができません。エラーメッセージからブロードキャストの問題というのはわかるのですが、解決方法がわかりません。

2

追加修正」

2018/11/03 13:45

投稿

Uta_fai
Uta_fai

スコア18

title CHANGED
File without changes
body CHANGED
@@ -105,7 +105,7 @@
105
105
  ### 試したこと
106
106
 
107
107
  ファイルネームの拡張子を.npzに変えたりしました。
108
- audio はnp.darrayのlist
108
+ audio はnp.darrayのlist 次元数は2です。
109
109
  label は整数のlist
110
110
  filename は元ファイルのパスを保存しているlistであることをtype()によって確認しました。
111
111
 

1

コードのインデントを修正しました。

2018/11/03 13:45

投稿

Uta_fai
Uta_fai

スコア18

title CHANGED
File without changes
body CHANGED
@@ -27,13 +27,10 @@
27
27
  555
28
28
 
29
29
  ValueError: could not broadcast input array from shape (20,883) into shape (20)
30
- エラーメッセージ
30
+ #コード
31
+
31
32
  ```
32
33
 
33
- ### 該当のソースコード
34
-
35
- Python
36
- ソースコード
37
34
  import librosa
38
35
  import os
39
36
  import numpy as np
@@ -56,21 +53,23 @@
56
53
  apath = os.path.join(angry,aud)
57
54
  x,fs = librosa.load(apath,sr=44100)
58
55
  mfccs= librosa.feature.mfcc(x,sr=fs)
59
-
56
+ #print (mfccs.shape)
57
+ #print(type(mfccs))
60
58
  audio.append(mfccs)
61
59
  if(max<mfccs.shape[1]):
62
60
  max = mfccs.shape[1]
63
61
  la = 0
64
62
  label.append(la)
65
63
  name.append(aud)
66
-
64
+ #print(type(audio))
67
65
 
68
66
  print("33%")
69
67
  for aud in normall:
70
68
  apath = os.path.join(normal,aud)
71
69
  x,fs = librosa.load(apath,sr=44100)
72
70
  mfccs= librosa.feature.mfcc(x,sr=fs)
73
-
71
+ #print (mfccs.shape)
72
+ #print(type(mfccs))
74
73
  audio.append(mfccs)
75
74
  if(max<mfccs.shape[1]):
76
75
  max = mfccs.shape[1]
@@ -83,6 +82,8 @@
83
82
  apath = os.path.join(happy,aud)
84
83
  x,fs = librosa.load(apath,sr=44100)
85
84
  mfccs= librosa.feature.mfcc(x,sr=fs)
85
+ # print (mfccs.shape)
86
+ #print(type(mfccs))
86
87
  audio.append(mfccs)
87
88
  if(max<mfccs.shape[1]):
88
89
  max = mfccs.shape[1]
@@ -100,6 +101,7 @@
100
101
  print(max)
101
102
  print("finish")
102
103
 
104
+ ```Python
103
105
  ### 試したこと
104
106
 
105
107
  ファイルネームの拡張子を.npzに変えたりしました。