Error in converting Matlab to python

Asked

Viewed 57 times

0

I intend to convert the following function into Python:

Função Matlab
cn = reshape(repmat(sn, n_rep, 1), 1,[]);

resultado matlab

cn =

  Columns 1 through 23

     1     1     1     1     1     1     0     0     0     1     1     1     1     1     1     0     0     0     0     0     0     1     1

  Columns 24 through 46

     1     1     1     1     1     1     1     0     0     0     1     1     1     1     1     1     0     0     0     1     1     1     0

  Columns 47 through 69

     0     0     0     0     0     1     1     1     1     1     1     1     1     1     1     1     1     0     0     0     1     1     1

  Columns 70 through 92

     1     1     1     1     1     1     1     1     1     1     1     1     0     0     0     1     1     1     0     0     0     1     1

  Columns 93 through 115

     1     0     0     0     0     0     0     0     0     0     0     0     0     1     1     1     1     1     1     0     0     0     1

  Columns 116 through 138

     1     1     0     0     0     0     0     0     0     0     0     1     1     1     1     1     1     0     0     0     0     0     0

  Columns 139 through 161

     0     0     0     1     1     1     1     1     1     1     1     1     0     0     0     1     1     1     1     1     1     0     0

  Columns 162 through 184

     0     0     0     0     0     0     0     1     1     1     0     0     0     1     1     1     0     0     0     1     1     1     0

  Columns 185 through 207

     0     0     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     0     0     0     0     0     0

  Columns 208 through 230

     0     0     0     1     1     1     0     0     0     1     1     1     0     0     0     1     1     1     0     0     0     0     0

  Columns 231 through 253

     0     0     0     0     1     1     1     0     0     0     0     0     0     1     1     1     1     1     1     1     1     1     1

  Columns 254 through 276

     1     1     0     0     0     1     1     1     1     1     1     0     0     0     1     1     1     0     0     0     0     0     0

  Columns 277 through 299

     1     1     1     1     1     1     1     1     1     0     0     0     1     1     1     0     0     0     0     0     0     0     0

  Columns 300 through 322

     0     0     0     0     1     1     1     0     0     0     1     1     1     0     0     0     1     1     1     0     0     0     1

  Columns 323 through 345

     1     1     1     1     1     1     1     1     0     0     0     0     0     0     0     0     0     1     1     1     0     0     0

  Columns 346 through 368

     1     1     1     1     1     1     1     1     1     0     0     0     0     0     0     0     0     0     1     1     1     0     0

  Columns 369 through 391

     0     1     1     1     1     1     1     1     1     1     0     0     0     0     0     0     0     0     0     1     1     1     0

  Columns 392 through 414

     0     0     1     1     1     0     0     0     0     0     0     0     0     0     0     0     0     1     1     1     1     1     1

  Columns 415 through 437

     1     1     1     0     0     0     1     1     1     1     1     1     0     0     0     1     1     1     0     0     0     0     0

  Columns 438 through 460

     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1     1     1     1

  Columns 461 through 483

     1     1     0     0     0     0     0     0     0     0     0     1     1     1     0     0     0     0     0     0     1     1     1

  Columns 484 through 506

     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1     1     1     1     1     1     1     1

  Columns 507 through 529

     1     0     0     0     0     0     0     0     0     0     1     1     1     0     0     0     0     0     0     0     0     0     1

  Columns 530 through 552

     1     1     1     1     1     1     1     1     0     0     0     1     1     1     0     0     0     1     1     1     0     0     0

  Columns 553 through 575

     1     1     1     0     0     0     0     0     0     1     1     1     1     1     1     0     0     0     1     1     1     1     1

  Columns 576 through 598

     1     0     0     0     0     0     0     0     0     0     0     0     0     1     1     1     1     1     1     1     1     1     1

  Columns 599 through 621

     1     1     1     1     1     0     0     0     1     1     1     1     1     1     0     0     0     1     1     1     1     1     1

  Columns 622 through 644

     1     1     1     1     1     1     1     1     1     0     0     0     0     0     0     0     0     0     0     0     0     1     1

  Columns 645 through 667

     1     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1     1     1     0

  Columns 668 through 690

     0     0     0     0     0     1     1     1     1     1     1     0     0     0     0     0     0     0     0     0     0     0     0

  Columns 691 through 713

     1     1     1     0     0     0     1     1     1     1     1     1     0     0     0     0     0     0     0     0     0     0     0

  Columns 714 through 736

     0     0     0     0     1     1     1     0     0     0     0     0     0     1     1     1     0     0     0     1     1     1     1

  Columns 737 through 759

     1     1     0     0     0     1     1     1     0     0     0     0     0     0     1     1     1     1     1     1     1     1     1

  Columns 760 through 768

     0     0     0     0     0     0     1     1     1

In python I have thus converted function

cn=np.arange(sn,n_rep).reshape(1)

outworking

cn=np.arange(sn,n_rep).reshape(1)

TypeError: only length-1 arrays can be converted to Python scalars

how I can accomplish the same way as Matlab, which I have to change?

  • Not for nothing, but putting the whole matrix in this way doesn’t help much. Putting the dimensions relevant to the problem does. If you need this date (I don’t think so, but...), put the Setting numeric display in the option compact, so you only get relevant lines of text.

  • Explain what you want to do help a lot tb! How fluent in Matlab and python I know exactly what you want to do but show effort in making a clear question helps the site and other users. It shows that you tried to solve, not just wanting someone to do your job.

  • Where do I put the Numeric display? in the Matlab?

  • and how I do or what function does in python?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.