My Coding >
Programming language >
Python >
Python libraries and packages >
Python NumPy >
How to make random Numpy 2D array with different range in every column
How to make random Numpy 2D array with different range in every columnSometimes it is necessary to generate set of objects with random properties. Every object have few parameters which can be defined in different ranges and it is necessary to generate all of them in one go. This task is refereed to the question: How to make random Numpy 2D array with different range in every column. Example of task for making random Numpy 2D array with different range in every columnLet’s consider simple task. We have 3 dimensional box with sizes A, B and C, and in this box we need randomly place N particles which mass can change form X to Y. Therefore, we need to make array with N rows and 4 columns in each row Generating random arrayFirst of all, it is necessary to define lists with lowest and highest possible parameters:.
And then, it is necessary to call function numpy.random.uniform with giving all these parameters:
Final codeThe final code with some values will be:
and the output will be something like:
|
Last 10 artitles
9 popular artitles
|
|
© 2020 MyCoding.uk -My blog about coding and further learning. This blog was writen with pure Perl and front-end output was performed with TemplateToolkit. |