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

Python Sklearn import error for scaler, pdalda file error?
PyYAML YAML load_all to Objects (nicely)
ttf_lookup_cache attribute not found in FontManager when using plot()
How to sort keys of dict by values?
a data structure with key as a cluster of words and value as a single word or string
Disable python warnings only for specific module via commandline
Error running GAE tutorial code - Guestbook
How to create a running total- Python [closed]
Unbuffered Python Subrocess PIPE
Django runserver syntax error
How to parse the string into list of tuples
Make instance methods global in module?
try-finally with SqlAlchemy: is this a good habit?
Bokeh not handling colors properly with ColumnDataSource
Psychopy MovieStim3: pausing errors
Django Mysql Complex annotations require an alias

Categories

HOME
makefile
swift
symfony
app-inventor
amazon-swf
firebase-app-indexing
ocaml
jasmine
agile
ubuntu-12.04
matplotlib
zend-framework2
ios10
gspread
ext.net
sequelize.js
urlencode
dropbox
google-classroom
pjsip
wordpress-theming
rapidjson
riak
uicollectionview
internet-explorer-8
boolean-expression
sonarqube-msbuild-runner
plsqldeveloper
embedly
scalaz7
dspic
remove-method
rworldmap
azure-servicebus-queues
jquery-waypoints
tflearn
excel-2013
multichoiceitems
invoke-command
xor
clockwork
salesforce-chatter
node-horseman
von-neumann
geomesa
boilerplate
deepstream.io
upsert
ti-basic
gist
sapui
cgcontext
etherpad
httplib2
svn-merge
payu
tuxedo
django-filer
linkageerror
codesign
console-redirect
scriptlet
asp.net-mvc-partialview
amazon-kcl
loopj
registrykey
connection-reset
cpu-cores
mdm-zinc
c++-actor-framework
django-1.6
proximity
tcpreplay
ultrawingrid
argument-passing
bsp
neoload
voldemort
dbsetup
map-force
android-json-rpc
chrome-for-android
sslexception
robospice
onselect
nimrod
stagefright
justgage
cgimageref
arbor.js
zend-framework-modules
mozart-mvc
sequelpro
icefaces-3
rose-db-object
applicationcontext
file-exists
userid
flexicious
querystringparameter
paintcomponent
nagle
rijndael
getresource
osx-leopard
surefire
openvg
evb





Mobile Apps Dev
Database Users
javascript
java
csharp
php
android


MS Developer
developer works
python
ios
c
html
jquery


RDBMS discuss