社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
私信  •  关注

I'mahdi

I'mahdi 最近创建的主题
I'mahdi 最近回复了
3 年前
回复了 I'mahdi 创建的主题 » 将numpy数组转换为numpy列python[duplicate]

你可以用 transpose 对于2d阵列,您可以看到可以使用的输出的差异 .reshape(-1,1) 如下所示:

>>> x.reshape(-1,1)
array([[1],
       [2],
       [3]])

或者你可以在这篇文章中读到更多细节 thread 试试这个:

>>> np.array([x]).T

>>> np.transpose([x])
3 年前
回复了 I'mahdi 创建的主题 » 在python中通过相邻字母计数转换字符串

collections.Counter ,那么如果 count_of_char > 1 设置 count 其他设置 '' 如下所示:

>>> from collections import Counter
>>> st = 'assdggg'
>>> cnt_chr = Counter(st)
>>> cnt_chr
Counter({'a': 1, 's': 2, 'd': 1, 'g': 3})

>>> ''.join(f"{'' if cnt==1 else cnt}{c}" for c , cnt in cnt_chr.items())
'a2sd3g'
3 年前
回复了 I'mahdi 创建的主题 » 在Python中,如何在打印时解压缩嵌套列表中的子列表

你可以用 itertools.chain 如下所示:

>>> from itertools import chain
>>> sl=[[1,2,3],[4,5,6],[7,8,9]]
>>> print(*(chain.from_iterable(sl)),sep="\n")
1
2
3
4
5
6
7
8
9