# 向量化 Vectorization

h = X' * theta （這裏的X‘表示X的轉置）

----------------------------------------------------------

You can use the mean() and sigma() functions to get the mean and std deviation for each column of X. These are returned as row vectors (1 x n)

Now you want to apply those values to each element in every row of the X matrix. One way to do this is to duplicate these vectors for each row in X, so they're the same size.

One method to do this is to create a column vector of all-ones - size (m x 1) - and multiply it by the mu or sigma row vector (1 x n). Dimensionally, (m x 1) * (1 x n) gives you a (m x n) matrix, and every row of the resulting matrix will be identical. （這個方法很妙！）

Now that X, mu, and sigma are all the same size, you can use element-wise operators to compute X_normalized.

Try these commands in your workspace:

``` 1 X = [1 2 3; 4 5 6]
2 % creates a test matrix
3 mu = mean(X)
4 % returns a row vector
5 sigma = std(X)
6 % returns a row vector
7 m = size(X, 1)
8 % returns the number of rows in X
9 mu_matrix = ones(m, 1) * mu
10 sigma_matrix = ones(m, 1) * sigma```