網站首頁 編程語言 正文
字符串轉list數組
str = '1,2,3'
arr = str.split(',')
gpu_ids分配
name = opt.name
gpu_ids =[ int(item) for item in opt.gpu_ids.split(',')]
# set gpu ids
if len(gpu_ids) > 0:
torch.cuda.set_device(gpu_ids[0])
list數組轉字符串
字符串類型list:
arr = ['a','b']
str = ','.join(arr)
數字型list:
arr = [1,2,3]
str = ','.join(str(i) for i in b)
二維list數組轉string:
先轉numpy數組,再遍歷轉str:
import os
import numpy as np
centroids= [[1,2],[3,4]]
centroids=np.asarray(centroids)
anchors = centroids.copy()
widths = anchors[:, 0]
sorted_indices = np.argsort(widths)
out_string=""
for i in sorted_indices:
out_string += str(int(anchors[i, 0] * 416)) + ',' + str(int(anchors[i, 1] * 416)) + ', '
print("str", out_string[:-2])
延伸閱讀:python中的字符數字之間的轉換函數
int(x [,base ]) ? ? ? ? 將x轉換為一個整數 ? ?
long(x [,base ]) ? ? ? ?將x轉換為一個長整數 ? ?
float(x ) ? ? ? ? ? ? ? 將x轉換到一個浮點數 ? ?
complex(real [,imag ]) ?創建一個復數 ? ?
str(x ) ? ? ? ? ? ? ? ? 將對象 x 轉換為字符串 ? ?
repr(x ) ? ? ? ? ? ? ? ?將對象 x 轉換為表達式字符串 ? ?
eval(str ) ? ? ? ? ? ? ?用來計算在字符串中的有效Python表達式,并返回一個對象 ? ?
tuple(s ) ? ? ? ? ? ? ? 將序列 s 轉換為一個元組 ? ?
list(s ) ? ? ? ? ? ? ? ?將序列 s 轉換為一個列表 ? ?
chr(x ) ? ? ? ? ? ? ? ? 將一個整數轉換為一個字符 ? ?
unichr(x ) ? ? ? ? ? ? ?將一個整數轉換為Unicode字符 ? ?
ord(x ) ? ? ? ? ? ? ? ? 將一個字符轉換為它的整數值 ? ?
hex(x ) ? ? ? ? ? ? ? ? 將一個整數轉換為一個十六進制字符串 ? ?
oct(x ) ? ? ? ? ? ? ? ? 將一個整數轉換為一個八進制字符串 ??
chr(65)='A'
ord('A')=65
int('2')=2;
str(2)='2'
原文鏈接:https://blog.csdn.net/jacke121/article/details/80613561
- 上一篇:沒有了
- 下一篇:沒有了
相關推薦
- 2023-02-04 Go語言中websocket的使用demo分享_Golang
- 2022-04-22 Number精度超了如何解決
- 2022-08-17 C++詳細分析lambda表達式的本質_C 語言
- 2023-07-31 Echarts多個圖表自適應窗口大小
- 2022-02-17 判斷一個字符串中是否包含另一個字符串
- 2022-07-02 jquery實現無縫輪播圖_jquery
- 2023-03-17 一文掌握git?push命令_相關技巧
- 2023-01-08 基于C#實現屏幕取色器的示例詳解_C#教程
- 欄目分類
-
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支