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

Delete Python module from disk after import while keeping it available in memory?
Create with imshow the same plot as pcolormesh [duplicate]
realitive import inside zipimport python
Google App Engine unable to find dev_appserver.py
reading last line of txt file in python and change it into variable to make calculation
What is the best way to merge multiple dictionaries?
Python 2.7: When importing into dataframe, I get IO error 'file does not exist', even when I provide absolute path
sphinx documentation: split a python source into sections, using autodoc
Installing dependencies of debian/control file
Why does Python's SysLogHandler require an address?
How to convert a .pptx to .pdf using Python
Combining two dictionaries by merging its values in a sorted list
SSH to a server and exit Python script (in the same shell)
What does this if .. and not statement mean?
Flask CORS - no Access-control-allow-origin header present on a redirect()
matplotlib: ylabel on the secondary y-axis with manual tick placing

Categories

HOME
d
amazon-product-api
is-empty
file-io
apiconnect
nodemailer
shipping
dropbear
jboss-eap-7
cartodb
camera-calibration
future
cosmicmind
eclipse-luna
sendkeys
scenebuilder
riak-ts
redux-observable
zoomcharts
aptana
primes
mousewheel
jive
android-fragmentactivity
backpropagation
csh
compare-and-swap
vcard
reactiveui
dhtmlx-scheduler
superscript
ioc-container
getjson
ifstream
von-neumann
sidr
lexical-analysis
code-composer
taglib
crop
upsert
rkt
catia
3scale
mbaas
mcrypt
project-template
tomee
ng2-material
mercurial-hook
mongo-c-driver
selecteditem
eml
android-recyclerview
drf-nested-routers
self-hosting
datainputstream
persistence.xml
fabric-twitter
stream-framework
debian-based
low-level
ticket-system
c++-actor-framework
jquery-autocomplete
formvalidation-plugin
funq
author
proxies
operations
circos
facebook-sdk-3.1
installshield-2009
execvp
va-list
sttwitter
ng-pattern
argb
apache2.2
htmltextwriter
dynamic-data
ubuntu-11.10
cadisplaylink
datarepeater
objective-c-protocol
selectmanycheckbox
authenticode
junit3
libavformat
loadui
clients
google-instant
oggvorbis
evb
ajaxpro

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