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

There is a duplicate line showed when calling a __init__ in Python script
trouble with mousewheel + scrollbars in tkinter
Python Cutting a string on a certain point
Ansible become_user error UnicodeEncodeError: 'ascii' codec can't encode character
Dynamic way to create new columns as a function of existing columns in pandas
polymorphic dispatch: distinguishing Python integers vs. floating-point numbers vs. strings
HTCondor output files: obtain created directory
getting select values with flask [duplicate]
Tensorflow tf.matmul example is incorrect?
drawing flower with python turtle
Python while loop iteration does not work
Rows not displaying properly in Tkinter GUI
Getting InvalidArgumentError in Tensorflow
Django - 2 URLS with same regex, but different variables and views
Parse headers with urllib2 if there is a duplicate [duplicate]
Python histogram outline

Categories

HOME
shopify
oauth
jsviews
raspbian
firebase-app-indexing
google-tag-manager
boost-thread
otrs
avro
playframework
ubuntu-12.04
apollo
adsense
devstack
websphere-liberty
deeplearning4j
ndis
uiview
event-log
medium-editor
cross-platform
scenebuilder
off-canvas-menu
atlassian-plugin-sdk
sql-update
apple-tv
hhvm
rworldmap
auditing
branch
partial-application
multichoiceitems
strophe
oracle-xml-db
spring-insight
canvasjs
google-drive-realtime-api
modelandview
openpgp
image-compression
silverlight-3.0
rule
onbackpressed
pdftk
ajp
double-buffering
data-integration
windows-firewall
tiddlywiki
pluck
ruby-on-rails-2
httplib2
restivejs
pdflib
radians
uiprogressview
metalsmith
gherkin
kendo-combobox
squirrel
search-regex
matcaffe
registrykey
sevenzipsharp
calibration
divide-by-zero
findcontrol
cpu-cores
multipleselection
hana-xs
start-job
client-side-validation
utf-32
candidate-key
qtestlib
vcl
snmp4j
csplit
valence
factors
anjuta
crystal-reports-10
ksoap2
circos
visual-studio-addins
sql-server-2012-web
windows-update
client-library
graph-coloring
marmalade-edk
crocodoc
applicationcontext
driving-directions
flash-cs5.5
external-assemblies
code-design
dirty-data
configurable
project-lifecycle

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