Review - Cipher

Stat 251

2026-02-05

Homework 3

  • graded with feedback

  • almost done :)

Vector to matrices

default in R is to fill columns first

x <- 1:9
matrix(x, ncol=3)
     [,1] [,2] [,3]
[1,]    1    4    7
[2,]    2    5    8
[3,]    3    6    9

Vector to matrices

in python rows are filled first! order="F" changes that:

import numpy as np
x = np.arange(1, 10)
matrix_x = x.reshape(-1, 3)
print(matrix_x)
[[1 2 3]
 [4 5 6]
 [7 8 9]]
matrix_x = x.reshape(-1, 3, order="F")
print(matrix_x)
[[1 4 7]
 [2 5 8]
 [3 6 9]]

Indices

The 18th element in a vector in R has index 18.

The 18th element in a vector in python has index 17 - same with columns! You need to keep that difference in mind

Extra Credit

LLMs have a bad rep for creating meh text and fabulating on facts.

What they are (usually) great for, are translations from one programming language to another.

For extra credit:

Take your code from your preferred language, and let an LLM translate it for you into the other language. Provide the code and describe your experience.

Next