确定如何从Python中的一组向量中找到特定向量。

huangapple go评论71阅读模式
英文:

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 with u[:, 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.

huangapple
  • 本文由 发表于 2023年3月12日 18:44:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/75712569.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定