例如,对于矩阵 A,我们有
A.dot(A) = B
现在我有B,想得到A。我尝试过np.sqrt(B),但这只能得到B的每个数字的平方根,而不是A。我在网上搜索,但没有找到。
NumPy 有没有办法获得 A ?
例如
import numpy as np
ar = np.random.randint(low=1, high=5, size=(4,4))
ar2 = ar.dot(ar)
ar1 = np.sqrt(ar2)
Run Code Online (Sandbox Code Playgroud)
然后我们会发现ar1和ar不一样。如果我们现在知道 ar2,我们怎样才能得到 ar?
我想使用Python逐年绘制动态图。
X轴的轴将是12个月,在Matplotlib中该过程将是一个barh,如下代码所示:
import random
import datetime
import matplotlib.pyplot as plt
def get_percent():
today = datetime.date.today()
start = datetime.date(today.year, 1, 1)
diff = today - start
percent = diff.days/365.0
return percent
fig = plt.figure(figsize=(8,2))
ax = fig.add_subplot(1,1,1)
percent = get_percent()
ax.axis([0, 12, 0, 1])
month = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug','Sep', 'Nov', 'Dec']
ax.set_xticklabels(month)
ax.set_xlim(0, 100)
ax.barh(bottom=0.5,width=int(percent*100),height=0.2)
plt.show()
plt.close()
Run Code Online (Sandbox Code Playgroud)
但是在情节之后,xtick显示7月是一年中的100%,这不是我想要的。
我搜索了matplotlib的文档,但没有找到答案:(。我如何使x轴刻度线显示Jan-Dec,而barh显示年份的百分比?