siren99
siren99

Reputation: 195

How to make random N-dimensions by using Numpy?

I'm currently trying to make N-dimensional matrix.

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

In this code, I want to reduce the recursive 2 dimensions. For example, like the following array (though it doen not work):

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

Is there ways that meet my needs?

Thanks.

Upvotes: 4

Views: 103

Answers (1)

NPE
NPE

Reputation: 500357

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)

Upvotes: 3

Related Questions