python - Numpy 转置向量
问题描述
如何用 numpy 转置向量?我在尝试
import numpy as np
center = np.array([1,2])
center_t = np.transpose(center)
但它不起作用,我该怎么办?
解决方案
重塑应该可以解决问题。
center = np.array([1,2])
print(center.reshape(-1,1))
数组([[1],[2]])
但是,对于 n 维数组,这将转置数组。
print(center.T)
例如:
a = np.array([['a','b','c'],['d','e','f'],['g','h','i']])
print(a)
array([['a', 'b', 'c'],
['d', 'e', 'f'],
['g', 'h', 'i']], dtype='<U1')
print(a.T)
array([['a', 'd', 'g'],
['b', 'e', 'h'],
['c', 'f', 'i']], dtype='<U1')
推荐阅读
- flutter - 来自 URL 的颤振图像仅适用于模拟器,但不适用于物理设备
- c++ - SDL_Init_Everything 在 C 中失败
- networkx - OSMNX/networkx 投影断开节点
- vba - 以不同的设置时间间隔运行多个宏 vba 通过按钮开始 - 按钮停止
- ios - iOS:仪器挂起模拟器的应用程序启动模板
- shell - 使用带数字后缀的 awk 将大文件拆分为较小的文件
- webpack - 如何在没有端口的情况下在 localhost 上运行 webpack-dev-server
- coq - 引入假设然后立即对其执行另一种策略的策略
- reactjs - NextJs与动态路由——空参数场景如何处理?
- android - 无法在片段 [Android] 中将项目添加到我的 ListView