Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
From Matlab to Python
Hi all!

I am working on a sound classification project. I have written codes in Matlab, but I need to convert it into Python to use with Raspberry Pi. However, I am not very experienced in Python, so I could not convert some parts of the code.

Here is the Matlab version of the code;

close all

load output.mat
for i=2:41
r= floor(size(C1,1)/d);
for j=1:r

Here is the Python version which is created by me. However, I could not avoid errors.


output = np.concatenate((a1,a2,a3,a4,a5,a6,a7,a8,a9))


C1_Data = pd.DataFrame(reweightTarget, columns = ('Sound Class'))

for i in range(0,43):
C1 = output[i][0]
r = math.floor(C1.size/d)
for j in range (1,r):
m +=1 "
The error

"index(...) must be called with a collection of some kind 'Sound Class' was passed"

If you can help me solve the problem, I will be grateful.
First, please post code using the Python code marker on the editor toolbar. Blue and yellow python symbol. Otherwise indentation is lost and there may be indentation problems.

The error you get is that the columns = part of your dataframe definition has a single item, where a collection (list, for example) is necessary. If you put brackets [] around your 'Sound Class' that error will go away.

Other issues -
Minor point - range(0,43) the 0 is not needed
Single letter variable names make the code less readable and maintainable. Python style suggests variable names that describe the variable.
erbab likes this post

Possibly Related Threads…
Thread Author Replies Views Last Post
Photo Matlab to Python Sateesh 0 295 Nov-04-2020, 09:11 AM
Last Post: Sateesh
  Arrays in MATLAB and PYTHON cokhuatlanyeuthuongconhetmuc 2 562 Jul-24-2020, 10:47 AM
Last Post: cokhuatlanyeuthuongconhetmuc
  Matlab to Python -- Parallel Computing zistambo 1 580 Jun-10-2020, 04:59 PM
Last Post: pyzyx3qwerty
  Python v MatLab for graphs and plots CynthiaMoore 4 861 Apr-22-2020, 02:13 PM
Last Post: CynthiaMoore
  python equivalent to MATLAB xcov chai0404 2 1,212 Apr-02-2020, 10:29 PM
Last Post: chai0404
  Python equivalent of Matlab code kwokmaster 1 1,059 Mar-25-2020, 10:14 PM
Last Post: j.crater
  MATLAB to Python conversion stokd 10 1,683 Jan-19-2020, 09:14 PM
Last Post: stokd
  Help converting MATLAB triple-for loop to Python davlovsky 1 691 Oct-29-2019, 10:26 PM
Last Post: scidam
  Error -3 when opening matlab file in python python_newbie09 0 788 Aug-02-2019, 11:51 AM
Last Post: python_newbie09
  How can I save Python dictionaries in Matlab? jlostinco 1 1,057 Jul-04-2019, 11:35 PM
Last Post: scidam

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020