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

How to pass file pointer in dll routines using ctypes in python
unable insert jpeg into filemaker db with pyodbc : HY011 ODBC Error
How to pass parameter as pointer in Python [duplicate]
Combine text files into key/value
Python modules not found over terminal but on python shell, Linux
Can PyCharm automatically generate __init__(), __eq__() and __hash__() implementations?
Create multi-level index pandas dataframe from delimited string column
Cross referencing decorators
Best way to speed up the process of creating dictionaries when dealing with a large amount of netflow data in a .json file in Python?
OpenCV Python - No module named cv2 (again)
How to find isolated vertices?
Python SystemError: Parent module '' not loaded, cannot perform relative import [duplicate]
Scrapy crawlspider solution for a local site
Python django, is possible to present the output of a view directly in a html template?
Widgets become invisible when i shrink my window - Tkinter - Python
Python, Using the result of a local variable in another class?

Categories

HOME
jsf
caching
ember.js
sidekiq
app-inventor
npm
puzzle
winapi
angular-cli
facebook-graph-api
apache2
apple-numbers
console
jframe
shader
ng-admin
goutte
ipfs
eclipse-cdt
gatsby
informatica-powercenter
symfony-forms
future
multiple-monitors
riak-ts
derived
jsonserializer
flexlm
propel2
ejbca
marathon
rails-activerecord
novnc
printdocument
ui5
bus-error
upnp
ab-initio
cgal
getjson
postgresql-9.2
pdflatex
m2e
getline
fabric-digits
remote-server
jquery-cycle2
forecasting
office365connectors
fltk
alchemy.js
exiftool
sendgrid-templates
google-account
taglib
homekit
amazon-clouddrive
aqgridview
mouseclick-event
multi-agent
pluck
modelattribute
spyne
keycode
build-process
hspec
picasa
debugdiag
aescryptoserviceprovider
gameanalytics
scalar
linkageerror
multifile-uploader
windows-nt
mongoskin
eml
anythingslider
android-cursoradapter
persistence.xml
ubercart
cpu-cores
google-hadoop
shift-jis
guzzle6
low-level
belongs-to
proximity
mfmailcomposeviewcontroll
sgml
dbsetup
ksoap2
uipickerviewcontroller
chrome-for-android
sqljdbc
osx-snow-leopard
reporting-tools
objcmongodb
attachevent
socketstream
git-filter-branch
shim
xmlslurper
gdt
getstring
z-machine
signals2
v4l
querystringparameter
throttling
datamember
curljs
openvg
code-design
act
method-signature

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