簡體   English   中英

如何使用Numpy制作隨機N維?

[英]How to make random N-dimensions by using Numpy?

我正在嘗試制作N維矩陣。

import numpy as np
fitness_landscape = np.random.uniform (0, 1, size = (N, 2., 2., 2., 2.))

在這段代碼中,我想減少遞歸的2維。 例如,像下面的數組(雖然它不起作用):

import numpy as np
K = 4
fitness_landscape = np.random.uniform (0, 1, size = (N, 2. * K))

有沒有辦法滿足我的需求?

謝謝。

In [9]: K = 5

In [10]: fitness_landscape = np.random.uniform (0, 1, size = (N,) + (2,) * K)

In [11]: fitness_landscape.shape
Out[11]: (3, 2, 2, 2, 2, 2)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM