M
M
MOTORIST2015-10-10 14:28:34
Programming
MOTORIST, 2015-10-10 14:28:34

How to generate a rectangular matrix (of any dimension) with values ​​from 0 to A?

Example (n columns = 3 (can be anything), m rows = whatever, matrix value from 0 to 2 (can be anything)):

1 0 0
1 1 0
1 0 1
1 1 1
2 0 0
2 1 0
2 0 1
2 1 1
2 2 0
2 2 1
2 0 2
2 1 2
2 2 2

I took linear algebra a long time ago, and I don’t remember that there were such examples. I will be grateful for help.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Kitaev, 2015-10-10
@deliro

For example, like this (python):

from random import randint
a, n, m = map(int, input().split())
matrix = [[randint(0, a) for i in range(n)] for j in range(m)]

A
Antony, 2015-10-10
@RiseOfDeath

And what does linear algebra and mathematics in general have to do with it? You create on a heap (or make a dynamic array by other means of the PL and its libraries) an array of the required dimension of the desired type and fill it with the values ​​you need.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question