#2D Array Numpy

3 messages · Page 1 of 1 (latest)

jovial anchor
#

Question:

In the rest of the Task we measure code efficiency for the two methods as a function of the number of elements in the matrix. Define an array $N_t = 2^i$, where $i = 0, 1, 2, ... 12$. For each value of $N_t$ find the matrices $M_1$, $M_2$ (do not print them as they become large), and the time it took your code to do so, $t_1(N_t)$ and $t_2(N_t)$. Print your $t_N$ in a clear fashion.

Code from previous question
(1)

import numpy as np

def F1(N):
    M = np.zeros((N, N), dtype=int)

    M[:, 0] = np.arange(N)

    for row in range(1, N):
        for column in range(1, N):
            M[row][column] = M[row-1][column] + M[row-1][column-1]

    return M

M1 = F1(8)

print(M1)

(2)

def F2(N):
    M = np.zeros((N, N), dtype=int)

    M[:, 0] = np.arange(N)

    for row in range(1, N):
        M[row, 1:row + 1] = M[row-1, :row] + M[row-1, 1:row + 1]

    return M

M2 = F2(8)

print(M2)
umbral wasp
#

And?

jovial anchor