我该如何获取这段代码:
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
x=[1,2,3,4,5,6,7,8,9,10]
y=[1,1,1,2,10,2,1,1,1,1]
line, = ax.plot(x, y)
ymax = max(y)
xpos = y.index(ymax)
xmax = x[xpos]
arrow = ax.annotate('local max:' + str(ymax), xy=(xmax, ymax), xytext=(xmax, ymax + 2),
arrowprops=dict(arrowstyle = '-', connectionstyle = 'arc3',facecolor='red'))
#==============================================================================
# arrow.remove()
#==============================================================================
ax.set_ylim(0,20)
plt.show()
Run Code Online (Sandbox Code Playgroud)
并创建一个圆形标记(点)而不是箭头。我想保留箭头的文字。
我似乎找不到一种方法来绘制多个物体的轮廓。
输入图像:
代码:
import cv2
import numpy as np
#import image
img = cv2.imread('img.png', 0)
#Thresh
ret, thresh = cv2.threshold(img, 200, 255, cv2.THRESH_BINARY)
#Finding the contours in the image
_, contours, _ = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
#Convert img to RGB and draw contour
img = cv2.cvtColor(img, cv2.COLOR_GRAY2RGB)
cv2.drawContours(img, contours, 0, (0,0,255), 2)
#save output img
cv2.imwrite('output_img.png', img)
Run Code Online (Sandbox Code Playgroud)
输出:
仅绘制较大的对象轮廓。我将如何绘制这两个轮廓?
我正在努力进入numba gpu processing。我有这个MWE:
import numpy as np
import numba
@numba.njit
def function():
ar = np.zeros((3, 3))
for i in range(3):
ar[i] = (1, 2, 3)
return ar
ar = function()
print(ar)
Run Code Online (Sandbox Code Playgroud)
输出:
[[1. 2. 3.]
[1. 2. 3.]
[1. 2. 3.]]
Run Code Online (Sandbox Code Playgroud)
现在我想在我的gpu. 我尝试使用以下decorators:
@numba.njit(target='cuda')
@numba.njit(target='gpu')
@numba.cuda.jit
Run Code Online (Sandbox Code Playgroud)
这些都不起作用。以下是上面的错误消息decorators:
Traceback (most recent call last):
File "/home/amu/Desktop/RL_framework/help_functions/test.py", line 4, in <module>
@numba.jit(target='cuda')
File "/home/amu/anaconda3/lib/python3.7/site-packages/numba/core/decorators.py", line 171, in jit
targetoptions=options, **dispatcher_args)
File "/home/amu/anaconda3/lib/python3.7/site-packages/numba/core/decorators.py", line …Run Code Online (Sandbox Code Playgroud) 此代码绘制scatterplot带有渐变颜色的 a:
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(30)
y = x
t = x
plt.scatter(x, y, c=t)
plt.colorbar()
plt.show()
Run Code Online (Sandbox Code Playgroud)
但是我如何line用x和y坐标绘制渐变颜色?
感谢@parastoo,它现在可以工作了。我必须像这样启动开发服务器(2 个不同的终端选项卡):
vite --host=HOST_IP
php artisan serve --host=HOST_IP
Run Code Online (Sandbox Code Playgroud)
然后连接您的移动设备(已连接到您的 WiFi)以:
http://HOST_IP:PORT
Run Code Online (Sandbox Code Playgroud)
运行时可以在终端中看到HOST_IPvite --host
PORT--port=8000可以通过添加artisan命令来配置。
vite.config.js无需额外输入。
我正在使用惯性,一种整体方法来开发具有前端框架(vue如laravel后端)的应用程序。我正在尝试将移动设备从我的网络连接到我的开发服务器,该服务器vite使用php server:
vite
Run Code Online (Sandbox Code Playgroud)
php artisan serve
Run Code Online (Sandbox Code Playgroud)
该网站由 提供服务http://localhost:8000。来自如何公开“主机”以供外部设备显示?#3396我读到,你可以这样做:
vite --host
Run Code Online (Sandbox Code Playgroud)
这应该暴露你的网络:
vite v2.9.13 dev server running at:
> Local: http://localhost:3000/
> Network: http://192.xxxxxxxxx:3000/
ready in 419ms.
Run Code Online (Sandbox Code Playgroud)
但是当我尝试连接到手机上的网络 URL 时,this page can't be found. 我还尝试连接8000显示的端口this site …
我正在阅读一张excel表:
import pandas as pd
df = pd.read_excel('file.xlsx', usecols = 'A,B,C')
print(df)
Run Code Online (Sandbox Code Playgroud)
现在我想创建一个列表,其中表中的每一行都是字符串.另外我想在列表中的每个字符串的末尾添加一个'X':
keylist = []
list1, list2, list3 = df['A'].tolist(), df['B'].tolist(), df['C'].tolist()
for i in zip(list1, list2, list3):
val = map(str, i)
keylist.append('/'.join(val))
keylist += 'X'
print(keylist)
Run Code Online (Sandbox Code Playgroud)
一切都有效,除了"添加X"部分.这导致:
['blue/a/a1', 'X', 'blue/a/a2', 'X', ....
Run Code Online (Sandbox Code Playgroud)
但我想要的是:
['blue/a/a1/X', 'blue/a/a2/X',
Run Code Online (Sandbox Code Playgroud)
先谢谢.
我想将 aconventional loop转换为numba.jit函数并在内部测量其进程的时间。我尝试使用time模块,但它似乎与 numba 不兼容。
代码:
from numba import jit, jitclass
import time
@jit(nopython=True)
def harmonic_load_flow_func():
time1 = time.perf_counter()
calc = 0
for x in range(1000000):
calc += x
print('time: {}'.format(time.perf_counter() - time1))
if __name__ == '__main__':
for count in range(10):
harmonic_load_flow_func()
Run Code Online (Sandbox Code Playgroud)
输出:
C:\Users\Artur\Anaconda\python.exe C:/Users/Artur/Desktop/RL_framework/help_functions/test.py
Traceback (most recent call last):
File "C:/Users/Artur/Desktop/RL_framework/help_functions/test.py", line 14, in <module>
harmonic_load_flow_func()
File "C:\Users\Artur\Anaconda\lib\site-packages\numba\core\dispatcher.py", line 401, in _compile_for_args
error_rewrite(e, 'typing')
File "C:\Users\Artur\Anaconda\lib\site-packages\numba\core\dispatcher.py", line 344, in error_rewrite
reraise(type(e), e, None) …Run Code Online (Sandbox Code Playgroud) 我有这两个router-links,一个包含在li元素中,另一个应用了属性tag="li":
<router-link tag="li" :to="{ name: 'work'}">Work</router-link
<li><router-link :to="{ name: 'news'}">News</router-link></li>
Run Code Online (Sandbox Code Playgroud)
在浏览器中编译如下:
tag的属性是router-link为了替换而设计的吗html elements?浏览器(SEO 等)会以相同的方式识别这两个链接吗?我想缩短html与tag房产的时间,但不知道是否应该。
我怎样才能在这个 vue 组件中定位带有类的元素test:
<template>
<div id="test" class="test">
</div>
</template>
<script setup>
console.log(document.querySelector('.test'))
</script>
Run Code Online (Sandbox Code Playgroud)
该组件被导入到另一个组件中。控制台输出null.
javascript vue.js vuejs3 vue-composition-api vue-script-setup