第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

我的 Tetration(復(fù)數(shù))函數(shù)必須更好地矢量化(Python)

我的 Tetration(復(fù)數(shù))函數(shù)必須更好地矢量化(Python)

函數(shù)式編程 2022-11-29 17:18:34
受 3blue1brown 的啟發(fā),我正在嘗試用 Python繪制 Tetration函數(shù)的逃逸(散度)圖——類(lèi)似于維基百科上這張漂亮的圖形。def tetration_com(base, tol=10**-15, max_step=10**6):  # returns t, the infinite tetration of base.  # if t does not converge, the function returns an escape value, aka how fast it diverges..  t = 1.0  step = 0  escape = None  ln_base = cmath.log(base)  t_last = 0  try:    while(abs(t - t_last) > tol):      if(step > max_step):        raise OverflowError      t_last = t      t = cmath.exp(ln_base*t)   # [ base^t == e^(ln(base)*t) ]      step += 1  except(OverflowError):    t = None    escape = 1000/step    # the escape value is is inversely related to the number of steps it took    # us to diverge to infinity  return t, escape我試圖讓它與 meshgrid 一起工作,以便繪制 xy 平面上的逃逸圖。Python 不喜歡輸出是 2 個(gè)解壓縮的變量(限制或轉(zhuǎn)義)——我絕對(duì)可以通過(guò)拆分成兩個(gè)函數(shù)來(lái)解決這個(gè)問(wèn)題。但另一個(gè)問(wèn)題是復(fù)雜的數(shù)學(xué)運(yùn)算(cmath.log,cmath.exp)只適用于標(biāo)量......我試圖向量化函數(shù):nx, ny = 700, 500x, y = np.linspace(-3.5, 3.5, nx), np.linspace(-2.5, 2.5, ny)xv, yv = np.meshgrid(x, y)tetration_vec = np.vectorize(tetration_com)t, escape = tetration_vec(xv + yv*1j, max_step=500)但它永遠(yuǎn)在運(yùn)行。關(guān)于如何處理復(fù)雜數(shù)學(xué)運(yùn)算和矢量化的任何建議?
查看完整描述

1 回答

?
www說(shuō)

TA貢獻(xiàn)1775條經(jīng)驗(yàn) 獲得超8個(gè)贊

這是我最后如何繪制逃生圖:


def tetration_com(base, tol=10**-15, max_step=10**6, max_val=10**2):

  # returns t, the infinite tetration of base.

  # if t does not converge, the function returns an escape value

  # aka how fast it diverges..


  t = 1.0

  step = 0

  escape = None


  t_last = 0

  try:

    while(abs(t - t_last) > tol):

      if(step > max_step or abs(t) > max_val):

        raise OverflowError

      t_last = t

      t = pow(base, t)

      step += 1

  except(OverflowError):

    t = None

    escape = 1000/step

    # the escape value is is inversely related to the number of steps it took

    # us to diverge to infinity


  return t, escape

向量化輔助函數(shù):


def tetra_graph_escape(real, imag, tol=10**-15, max_step=10**3, max_val=10**2):

  return np.array([np.array([tetration_com(r + im*1j, tol=tol, max_step=max_step, max_val=max_val)[1]

                             for im in imag]) for r in real])

繪圖:


# graph our escape:

nx, ny = 700, 500

x, y = np.linspace(-3.5, 3.5, nx), np.linspace(-2.5, 2.5, ny)


val, escape = tetra_graph_conv(x, y), tetra_graph_escape(x, y)


import matplotlib.pyplot as plt


for r in range(len(escape)):

  for c in range(len(escape[0])):

    if escape[r][c] is None:

      escape[r][c] = -100


escape[460][250]


plt.contour(escape)


查看完整回答
反對(duì) 回復(fù) 2022-11-29
  • 1 回答
  • 0 關(guān)注
  • 106 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)