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

if-else, using the True and False statements on python. skulpt.org
Python: (Count positive and negative numbers and compute the average of numbers)
Replacing strings in rows of CSV
Having multiple objects in a dictionary
Find a specific header in a CSV file using python 3 code
Django model inheritance - Subclass instantiated as super when querying
python parse nginx log
how to convert alpha channel of the image to white color using opencv python?
R dcast equivalent in python pandas
Install Python 2.7.8 (64-bit) without replacing existing Python27 installation
Return only one field in JSON data
Creating hybrid properties automatically from SQLAlchemy Mixins
Errors when trying to install PIL with pip as well as pyscripter errors
How to locate an element by class name and its text in python selenium
How to install Pisa on Ubuntu [closed]
How to assign the objects of a large dict to smaller dicts in a particular ratio?

Categories

HOME
tensorflow
cntk
tinyos
sudo
android-viewpager
nixos
xlsx
datagrip
rapidjson
arm-template
ng-show
cython
ghost-inspector
binutils
rworldmap
searchbar
python-textprocessing
compare-and-swap
metis
kong
dss
cgal
pygooglechart
dhtmlx-scheduler
devforce
xor
encase
svnkit
strophe
construct-2
ipfw
preg-grep
geopy
data-extraction
passenger
precedence
text-files
tic-tac-toe
ttcn
matlab-cvst
context-free-language
rapidweaver
ajp
floor
chunked-encoding
jags
gist
jgraph
greenhills
rpostgresql
emoticons
spyne
vici
android-navigationview
uiprogressview
console-redirect
asp.net-mvc-partialview
except
android-viewholder
optionbutton
fabric-twitter
windowlistener
type-mismatch
pylearn
web-component-tester
sysfs
chaining
client-side-validation
orientation-changes
java-melody
tilestache
emma
argument-passing
codeigniter-a3m
zipalign
real-time-updates
vertical-scrolling
angularjs-timeout
tridion2009
caliper
expression-evaluation
datamember
goliath
windows-live-id
chdatastructures
visual-studio-2010-beta-2
dirty-data
standardized
visual-studio-dbpro
divx





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