英文:
Does specifying brackets for 1D arrays like [[ ]] make any change in the structure?
问题
以下是要翻译的内容:
这个p = np.array(
[[mu, sig
]])
与仅指定np.array(
[mu, sig
])
有何不同?
英文:
Does this p = np.array(
[[mu, sig
]])
make any change than just specifying np.array(
[mu, sig
])
?
答案1
得分: 2
是的,这两个表达式有区别。
[mu, sig]
是一个包含两个元素(mu
和 sig
)的数组。
[[mu, sig]]
是一个包含一个数组的数组。那个数组就是 [mu, sig]
,它也是一个包含两个元素(mu
和 sig
)的数组。所以 [[mu, sig]]
是一个二维数组(即数组的数组)。
编辑: 我最初说[[mu, sig]]
是一个包含一个元素的数组。虽然这是我对多维数组的理解方式,但由于这并不完全正确,这在评论中引发了讨论。[[mu, sig]]
仍然有两个元素,只是它们以二维的方式组织起来。
说[[mu, sig]]
只有一个元素就像说以下矩阵只有两个元素一样:
[ [1, 2, 3],
[4, 5, 6] ]
鉴于此,为了不让任何人感到困惑,我编辑了我的答案以澄清:[[mu, sig]]
是一个包含一个数组的数组。不能完全正确地说它只有一个元素。
英文:
Yes, there is a difference between the two expressions.
[mu, sig]
is an array with two elements (mu
and sig
).
[[mu, sig]]
is an array with one array inside it. That one array is [mu, sig]
, an array with two elements (mu
and sig
). So [[mu, sig]]
is a two dimensional array (i.e. an array of arrays).
Edit: I originally said that [[mu, sig]]
is an array with one element inside it. While that is the way I think about multi-dimensional arrays, it sparked a discussion in the comments because that is not 100% correct. [[mu, sig]]
still has two elements, only that they are organized in a two dimensional fashion.
Saying that [[mu, sig]]
has one element would be like saying that the following matrix has only two elements:
[ [1, 2, 3],
[4, 5, 6] ]
In light of this, and in order not to confuse anyone, I've edited my answer to clarify: [[mu, sig]]
is an array with one array inside it. It is not fully correct to say that it has only one element inside it.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论