網(wǎng)站首頁 編程語言 正文
字符串轉(zhuǎn)list數(shù)組
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數(shù)組轉(zhuǎn)字符串
字符串類型list:
arr = ['a','b']
str = ','.join(arr)
數(shù)字型list:
arr = [1,2,3]
str = ','.join(str(i) for i in b)
二維list數(shù)組轉(zhuǎn)string:
先轉(zhuǎn)numpy數(shù)組,再遍歷轉(zhuǎn)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中的字符數(shù)字之間的轉(zhuǎn)換函數(shù)
int(x [,base ]) ? ? ? ? 將x轉(zhuǎn)換為一個整數(shù) ? ?
long(x [,base ]) ? ? ? ?將x轉(zhuǎn)換為一個長整數(shù) ? ?
float(x ) ? ? ? ? ? ? ? 將x轉(zhuǎn)換到一個浮點數(shù) ? ?
complex(real [,imag ]) ?創(chuàng)建一個復(fù)數(shù) ? ?
str(x ) ? ? ? ? ? ? ? ? 將對象 x 轉(zhuǎn)換為字符串 ? ?
repr(x ) ? ? ? ? ? ? ? ?將對象 x 轉(zhuǎn)換為表達(dá)式字符串 ? ?
eval(str ) ? ? ? ? ? ? ?用來計算在字符串中的有效Python表達(dá)式,并返回一個對象 ? ?
tuple(s ) ? ? ? ? ? ? ? 將序列 s 轉(zhuǎn)換為一個元組 ? ?
list(s ) ? ? ? ? ? ? ? ?將序列 s 轉(zhuǎn)換為一個列表 ? ?
chr(x ) ? ? ? ? ? ? ? ? 將一個整數(shù)轉(zhuǎn)換為一個字符 ? ?
unichr(x ) ? ? ? ? ? ? ?將一個整數(shù)轉(zhuǎn)換為Unicode字符 ? ?
ord(x ) ? ? ? ? ? ? ? ? 將一個字符轉(zhuǎn)換為它的整數(shù)值 ? ?
hex(x ) ? ? ? ? ? ? ? ? 將一個整數(shù)轉(zhuǎn)換為一個十六進(jìn)制字符串 ? ?
oct(x ) ? ? ? ? ? ? ? ? 將一個整數(shù)轉(zhuǎn)換為一個八進(jìn)制字符串 ??
chr(65)='A'
ord('A')=65
int('2')=2;
str(2)='2'
原文鏈接:https://blog.csdn.net/jacke121/article/details/80613561
- 上一篇:沒有了
- 下一篇:沒有了
相關(guān)推薦
- 2023-11-20 如何設(shè)置樹莓派4B的頻率?
- 2023-05-13 python中數(shù)字列表轉(zhuǎn)化為數(shù)字字符串的實例代碼_python
- 2022-05-03 ASP.NET?Core基于滑動窗口實現(xiàn)限流控制_實用技巧
- 2022-12-11 Go?map發(fā)生內(nèi)存泄漏解決方法_Golang
- 2023-01-07 基于Go語言實現(xiàn)選擇排序算法及優(yōu)化_Golang
- 2022-04-28 WPF使用DockPanel停靠面板布局_實用技巧
- 2024-07-13 根據(jù)腳手架archetype快速構(gòu)建spring boot/cloud項目
- 2022-04-24 記錄一次nginx啟動失敗的解決過程_nginx
- 欄目分類
-
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支