Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Arrays in MATLAB and PYTHON
#3
import math
import numpy as np
from matplotlib import pyplot as plt
import pandas as pd

def fx(R, alpha):
    x = R*math.cos(alpha)
    y = R*math.sin(alpha)
    return x,y

alpha = np.linspace(0, math.pi*2, num = 10000)
Rmax = 100000
for i in range(alpha):
    (x[i], y[i]) = fx(Rmax, alpha[i])
Error:
TypeError Traceback (most recent call last) <ipython-input-14-8444e88ffbda> in <module> 2 alpha = np.linspace(0, math.pi*2, num = 10000) 3 Rmax = 100000 ----> 4 for i in range(alpha): 5 (x[i], y[i]) = fx(Rmax, alpha[i]) 6 TypeError: only integer scalar arrays can be converted to a scalar index
Here is my code and error.
Reply


Messages In This Thread
RE: Arrays in MATLAB and PYTHON - by buran - Jul-24-2020, 09:24 AM
RE: Arrays in MATLAB and PYTHON - by cokhuatlanyeuthuongconhetmuc - Jul-24-2020, 10:47 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Photo Matlab to Python Sateesh 0 1,697 Nov-04-2020, 09:11 AM
Last Post: Sateesh
  From Matlab to Python erbab 1 2,039 Oct-27-2020, 02:16 PM
Last Post: jefsummers
  Matlab to Python -- Parallel Computing zistambo 1 1,990 Jun-10-2020, 04:59 PM
Last Post: pyzyx3qwerty
  Python v MatLab for graphs and plots CynthiaMoore 4 3,086 Apr-22-2020, 02:13 PM
Last Post: CynthiaMoore
  python equivalent to MATLAB xcov chai0404 2 3,907 Apr-02-2020, 10:29 PM
Last Post: chai0404
  Python equivalent of Matlab code kwokmaster 1 3,485 Mar-25-2020, 10:14 PM
Last Post: j.crater
  No arrays in Python? twilkinson 2 1,820 Jan-29-2020, 04:42 PM
Last Post: ThiefOfTime
  MATLAB to Python conversion stokd 10 5,078 Jan-19-2020, 09:14 PM
Last Post: stokd
  Help converting MATLAB triple-for loop to Python davlovsky 1 2,005 Oct-29-2019, 10:26 PM
Last Post: scidam
  Python sorts all arrays instead of one. Alex009988 2 2,061 Sep-02-2019, 02:31 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

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