英文:
How to determine a specific vector from a set of vectors in python
问题
我有以下的二维向量 Ui,其中 i=1,...,1000
import numpy as np
n = 1000
u1 = np.random.uniform(0.5, 4.5, size=n)
u2 = 2 / u1 + np.random.normal(scale=0.09, size=n)
u = np.array([u1,u2])
如何确定第500个二维向量或 Ui 中的任意向量是什么?
英文:
I have the following two-dimensional vectors Ui for i=1,...,1000
import numpy as np
n = 1000
u1 = np.random.uniform(0.5, 4.5, size=n)
u2 = 2 / u1 + np.random.normal(scale=0.09, size=n)
u = np.array([u1,u2])
How can I determine what the 500th two-dimensional vector or an arbitrary vector in Ui is?
答案1
得分: 0
这里是翻译好的部分:
- "It's a little confusing to call these 'two-dimensional vectors'" 可能有点混淆,称这些为 '二维向量',
- "dimension" refers to (the length of) the shape of an array." "dimension" 指的是(数组的形状的长度),
- "For example, a vector is a one-dimensional array, a matrix is a two-dimensional array, and higher-dimensional arrays are also possible." 例如,向量是一维数组,矩阵是二维数组,还可以有更高维度的数组。
- "In particular,
u
is a two-dimensional array with shape(2, n)
." 特别地,u
是一个形状为(2, n)
的二维数组。 - "IIUC, you want to get the 500th (say) column of
u
, which is a one-dimensional array (vector) with two elements. You can do that withu[:, 499]
." 如果我理解正确,您想获取u
的第500列(例如),它是一个具有两个元素的一维数组(向量)。您可以使用u[:, 499]
来实现。 - "More information can be found in the NumPy documentation on indexing." 更多信息可以在NumPy索引文档中找到。
英文:
It's a little confusing to call these "two-dimensional vectors", because in NumPy, "dimension" refers to (the length of) the shape of an array. For example, a vector is a one-dimensional array, a matrix is a two-dimensional array, and higher-dimensional arrays are also possible. In particular, u
is a two-dimensional array with shape (2, n)
.
IIUC, you want to get the 500th (say) column of u
, which is a one-dimensional array (vector) with two elements. You can do that with u[:, 499]
.
More information can be found in the NumPy documentation on indexing.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论