python


How to convert a Python list of lists to a 2D numpy array for sklearn.preprocessing


I currently have a list which contains all of my input for an sklearn classifier. Each element in that list is a list of features, where each element represents a song in my dataset.
I need to convert this structure to a 2D numpy array so I can scale my data via sklearn's preprocessing. This is proving to be very difficult.
y = []
all_feats = []
for song in data:
mfccs_in_song = song[0]
oned_mfccs_in_song = []
for frame in mfccs_in_song:
for m in frame:
oned_mfccs_in_song.append(m)
all_feats.append(oned_mfccs_in_song)
label = song[-1]
y.append(label)
Long story short, all_feats is that list of lists. It has a length of 600. How can I convert this to a numpy array for preprocessing? I have tried numerous things, including simply all_feats = np.array(all_feats), however that does not work.
That error suggests that all_feats may not have sublists of the same size. Take a look at its contents, and once you figure out what's the right length for the sublists, and how to prune the extra elements out, you can run all_feats = np.array(all_feats) and it should work!
Take a look at the answers in this link for more explanation.

Related Links

Weird type error arising when I add to a database using SQL Alchemy
Python for loop causes system crash
Class object variable = none
Print last <td> in beautiful soup
Break python regular expression with escape into multiple lines
Django querying with Through table properties
How to get the 1st, 3rd and 5th element from an array in Python?
Unexpected unindent
Obscurity in “lambda” function in python
Having trouble getting “more like this” to return any results in Haystack using Elastic Search backend
Linear interpolation within groups
Is it possible to turn a widget [Kivy]
Want to create a thumbnail(25,25) of an Image of size (181,256) using python
python code to get values from json data
Math domain error when trying to graph equation of circle with polar coordinates in python
Converting base 6 to decimal and vice versa in Python? [closed]

Categories

HOME
sas
pug
admin-on-rest
redis
itext
rotation
freepascal
ubuntu-16.04
avro
iis-7.5
filter
file-io
urlencode
spring-cloud-contract
sudo
ng-admin
goutte
automata
multiple-monitors
event-log
plupload
cython
sensu
google-ima
jquery-form-validator
facebook4j
remove-method
bootstrap-typeahead
kong
codelite
dpi
vertex-buffer
gettext
cross-entropy
lexical-analysis
dart-pub
constants
taglib
rich-text-editor
ideone
tuleap
slot
google-maps-ios
ingres
bettercms
project-template
android-navigationview
iostat
manifest.mf
git-annex
webkit2
pax-web
brython
mercurial-hook
gmsmapview
android-snackbar
on-duplicate-key
git-checkout
omnifocus
scala-2.11
getimagedata
chrome-for-android
pyjade
bigint
modeshape
dllexport
va-list
html-form-post
haskell-platform
surveyor-gem
blockingqueue
pstree
hashalgorithm
throttling
electronic-signature
gethashcode
audiostreamer
rijndael
libavformat
msn
osx-leopard
unreachable-code
gwt-2.2-celltable
openvg
savestate
dotproject

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App