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

Send data from C Parent to Python Child and back using a Pipe
AES cipher process creation
Python list object is not callable for a list of integers [duplicate]
What does the following error message mean for an inverse matrix?
Python3/SQLite3 | How to create multiple tables from a list or list of tuples?
Animation of circles on python
Python using XlWings UDF works in debug mode but not in release mode?
convert list to dataframe in python
How can I complete this program without a break statement?
HTTP Client in Python 3 - no cookies send
Finding the index of a header in a structured array for a part of the header name
sqlite3.OperationalError: unrecognized token: “{”
How to upload Image Files on Shared Host/ Shared Folder using Django, Python?
How can I end an infinite loop with socket operations inside after finishing current iteration?
Python removing invalid ascii characters
Select a valid choice is not one of the available choices

Categories

HOME
jsf
payment-gateway
crate
nuxeo
windows-7
visual-studio-2013
boost-thread
parse-server
mainframe
codeeffects
is-empty
flyway
checksum
terrain
iis-7.5
filter
internet-explorer-11
pca
dropbear
dryioc
mongodb-query
line-api
sql-tuning
reduction
ng2-dragula
statusbar
countif
spring-ws
spring-test
fabric
samsung-mobile
rhandsontable
web-frontend
protobuf-net
phpspreadsheet
nlb
discord.net
initializer
deepstream.io
active-model-serializers
jrules
taglib
spring-bean
matlab-cvst
rhel6
ticker
forerunnerdb
jszip
castle-dynamicproxy
mercury
date-range
ingres
restivejs
sql-server-administration
pdflib
packagemaker
mix
gherkin
database-backups
soda
codesign
date-format
brackets-shell
plone-3.x
coldfusion-7
sourcegear-vault
prezto
ubercart
searchkick
node-imagemagick
snmp4j
power-law
boost-test
colt
alertifyjs
phpdocx
ifft
dbsetup
xenocode
baucis
installshield-2011
icsharpcode
bulbs
moq-3
unions
gjs
django-nose
gtk2hs
symbol-server
hadoop-plugins
revert
graph-layout
nt4
rd

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