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 , Pseudocode conversion with lists and for statements
How to share a list between two files [closed]
Removing phrase/sentence that \r\n is located randomly (R / Python)
Python Pandas - Splitting strings to columns (series to dataframe)
Creating a grid for a table within a text.grid in Python
Markdown for Reproducible Research in Python [closed]
How to make exception syntax from 2.** to 3.** work
Destroy an OptionMenu in Python
Python MultiPart POST Malformed
SQLite ORDER BY clause not working
How do I access various Outlook folders through Python using win32.client
python parser TypeError: Passing a bool to header is invalid
Python Pandas, slice rows from group in .groupby().apply()
Python argument types did not match c++ signature
Form not appearing using Django/HTML/Python [closed]
Class selector for a beginning of a game

Categories

HOME
google-apps-script
cakephp-3.x
vue.js
symfony
numpy
blockchain
cocos2d-x-3.0
phaser-framework
dataframe
avl-tree
requirejs
httpclient
xcode8.3
height
metronic
xamarin-studio
game-maker-studio-1.4
data-synchronization
cs-cart
qt-installer
dlib
activesync
x-frame-options
symfony2-easyadmin
ejs
medium-editor
grub2
eclipselink
thumbnails
statusbar
extractor
cronet
owl-api
system.data.sqlite
partial-application
pcre
thinking-sphinx
xor
encase
expand
ipfw
division
fabric-digits
von-neumann
powershell-remoting
vmd
issue-tracking
floating-accuracy
stereo-3d
rkt
fastq
archer
istorage
multi-agent
chrome-remote-desktop
etherpad
tofixed
launch
infinite-scroll
addin-express
atlassian-crowd
system.web.ui.webcontrols
cfeclipse
icefaces
firepath
spoofing
spark-cassandra-connector
nofollow
unsatisfiedlinkerror
linkageerror
date-format
freefem++
function-fitting
datasnap
python-winshell
programming-paradigms
ffserver
manjaro
es2015
jai
microblaze
google-admin-audit-api
humanizer
getimagedata
io.js
android-looper
lumx
visualstatemanager
zipalign
dynamic-proxy
angulartics
cilk-plus
javascriptmvc
multiple-login
entity-framework-4.1
ftp4j
vmware-server
ng-pattern
lame
fileconveyor
objcmongodb
fluidsynth
blockingqueue
shim
shared-objects
galaxy-tab
authenticode
clause
loadui
quick-search
trampolines
winsnmp
economics
data-entry
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