【发布时间】:2016-02-12 07:32:03
【问题描述】:
来自this post 我了解到 log10() 在评估 where 之前进行评估。简而言之,我不明白该问题中提供的答案。另外,为什么要先评估 log10(),这肯定会导致不必要的计算?
merge_y = np.where(n
import matplotlib.pyplot as plt
import numpy as np
n = np.arange(0, 10, 0.0001)
merge_y = np.where(n <= 1, 1, n * np.log10(n))
insertion_y = n*n
plt.plot(n, merge_y,'g')
plt.plot(n,insertion_y,'r')
plt.grid(True)
plt.xlabel('n')
plt.ylabel('T(n)')
plt.title('Time complexities of merge and insertion sort w/ input size n')
plt.show()
【问题讨论】:
-
您确实意识到,您尝试计算
log10(0),对吧? -
我看不到在哪里,对于 where(condition,a,b) 如果条件为假则不返回 b,如果条件为真则返回 a...
标签: python numpy logging where divide-by-zero