如何解决分配给uint Numpy数组中缺失值的值
由2个Python列表z
和x
构成一个numpy数组y
,其中y
的值可以为0
,而值{{1} }没有连续增加(即可以跳过值)。
由于x
的值也可以是y
,因此将0
中的缺失值也分配为z
会造成混淆。
避免这种混乱的最佳实践是什么?
0
解决方法
解决方案
您通常可以为# asgi.py
import os
from django.core.asgi import get_asgi_application
from websocket_app.websocket import websocket_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE','websocket_app.settings')
django_application = get_asgi_application()
async def application(scope,receive,send):
if scope['type'] == 'http':
# Let Django handle HTTP requests
await django_application(scope,send)
elif scope['type'] == 'websocket':
# handle websocket connections here
await websocket_application(scope,send)
else:
raise NotImplementedError(f"Unknown scope type { scope['type'] }")
# websocket.py
async def websocket_application(scope,send):
while True:
event = await receive()
if event['type'] == 'websocket.connect':
await send({
"type": "websocket.accept"
})
if event['type'] == 'websocket.disconnect':
break
if event['type'] == 'websocket.receive':
try:
# result = json.loads(event['text'])
await route(scope,event,send)
except Exception as e:
await send({
"type": "websocket.send","text": e.__repr__()
})
中不存在的索引分配np.nan
或其他任何值。
此外,不需要 for循环。您可以在一行中直接分配x
的所有值,如我在此处所示。
但是,由于要强制转换为 uint32 ,因此不能使用y
(why not?)。取而代之的是,您可以使用大量的选择(例如,np.nan
),这些数字在设计上不会显示在999999
中。有关更多详细信息,请参阅下面的参考部分中共享的链接。
y
参考文献
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。