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

decoding json in python
Python debugging, stop at particular output
Why an avi file can not be opened in OpenCV-Python
Can't compile msgpack Python extension under windows
Python sockets for a n-players game
HTMLParser or urllib2 unicode issue
How to stop PyCharm inserting spaces for fine alignment when reformating code?
Install NLTK with IronPyton for VS2012
pip install won't install on my machine
Integrating using scipy.integrate.simps
Problems with django and virtualenv
Returning when any Future in a list finishes
Python Django - matching query does not exist when using pk
R translation to Python
Are there downsides to using Python locals() for string formatting? [duplicate]
Compiled Python writing to Program Files

Categories

HOME
visual-studio-2015
redis
wmic
nuxeo
google-tag-manager
google-contacts
boost-thread
laravel-5.3
zend-framework2
xcode8.3
octopus-deploy
jboss-eap-7
cortex-a
dryioc
future
react-leaflet
rapidjson
medium-editor
yeoman-generator
clover
pycrypto
onsen-ui
http-method
switching
version-numbering
data-conversion
winscp
vegan
xor
encase
android-vpn-service
outsystems
web-audio-api
passenger
xen
rhel.net
ntfs-mft
tic-tac-toe
google-account
constants
pdftk
dojox.mobile
g1gc
paho
homekit
crop
ttcn
scalafx
nsjsonserialization
number-theory
livefyre
pinvoke
jgraph
pluck
mbaas
instruction-set
launch
static-code-analysis
selenium-firefoxdriver
iron.io
sqldatareader
alter
vst
activeweb
visible
pagekit
windows-nt
xmp
datainputstream
getrusage
application-loader
mptcp
urn
manjaro
debian-based
adodb
orientation-changes
adcolony
dache
bsp
korma
windows-mobile-6
robospice
pep8
client-library
cosm
plone-funnelweb
subtract
windows-phone-7-emulator
law-of-demeter
objectbrowser
coff
printing-web-page
qtembedded
opengl-es-lighting
dashcode
.app
rijndael
libavformat
camtasia
graniteds
multibyte-functions
opcodes
database-diagramming
ajaxpro
visual-studio-dbpro

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