简体   繁体   English

从三个一维数组制作一个 3d python 数组

[英]making a 3d python array from three 1d arrays

i am new in python and have a basic question:我是 python 新手,有一个基本问题:

I have three lists :我有三个列表:

a = [1, 2, 3]
b = [2, 4, 5]
c = [5, 7, 8]

What i want is an array that looks something like :我想要的是一个看起来像这样的数组:

x = np.array([1,2,5],[2,4,7],[5,7,8])

is there some on-line python trick to do this?是否有一些在线 python 技巧可以做到这一点?

np.vstack((np.array([1,2,3]), np.array([1,2,3]), np.array([1,2,3])))

甚至更简单

np.vstack(([1,2,3], [1,2,3], [1,2,3]))

Another simple way is using .T which transposes the matrix.另一种简单的方法是使用.T转置矩阵。

import numpy as np

a = [1, 2, 3]
b = [2, 4, 5]
c = [5, 7, 8]

np.array([a,b,c]).T

array([[1, 2, 5],
       [2, 4, 7],
       [3, 5, 8]])

试试zip(a, b, c) ,例如, x = np.array(*zip(a, b, c))官方文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从三个1D阵列创建3D表面图 - Creating a 3D surface plot from three 1D arrays 从三个1D数组创建一个numpy 3D坐标数组,第一个索引更改最快 - Creating a numpy array of 3D coordinates from three 1D arrays, first index changing fastest 从三个1D阵列创建一个numpy 3D坐标数组 - Creating a numpy array of 3D coordinates from three 1D arrays 从一维 arrays 创建 3D 阵列的有效方法 - Efficient way of creating a 3D array from 1D arrays 在Python中使用两个1D阵列(2D绘图)创建2D阵列(3D绘图)(用于计算希尔伯特谱) - Create a 2D array (3D plot) from two 1D arrays (2D plots) in Python (for calculating the Hilbert spectrum) 将1D数组插值到python中的3d中 - Interpolation of 1D array into a 3d in python 创建具有使用三个1D Numpy数组的值的3D数组 - Create 3D array with values which use three 1D Numpy arrays 如何通过计算欧几里得度量将三个一维 arrays 变成一个 3D 数组 - how to turn three 1D arrays into one 3D array by calculating the euclidian metric 来自3D阵列的1D图 - 1D plots from 3D array 当我收到错误Z时,如何使用python中的三个1D数组绘制3D表面图,必须在2维中。 如何将其转换为2D数组? - How to plot a 3D surface Plot using three 1D arrays in python as I am getting an error Z must be in 2 dimensional. How to convert it into 2D array?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM