2

How to write a matrix of $n\times 2$ where the first column is made of only 1's?

Suppose I have a vector x={.24,...,10}.

How can I get this

$\left( \begin{matrix} 1 & .24 \\ 1 & 21 \\ 1 & 33 \\ 1 & 11 \\ 1 & 10 \end{matrix}\right)$

How can I do that?

Help me please

I know how to write a 'normal' matrix, it's MatrixForm[{1,2},{1,1}] but how to give the form above?

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574

2 Answers2

5
col2 = {2.4, 21, 33, 11, 10};
Thread[{1, col2}]

{{1, 2.4}, {1, 21}, {1, 33}, {1, 11}, {1, 10}}

% // MatrixForm //TeXForm

$\left( \begin{array}{cc} 1 & 2.4 \\ 1 & 21 \\ 1 & 33 \\ 1 & 11 \\ 1 & 10 \\ \end{array} \right)$

Also

{1, #} & /@ col2 (* or Map[{1, #} &, col2] *)
col1 = ConstantArray[1, Length@col2];
Transpose[{col1, col2}]

both give

{{1, 2.4`}, {1, 21}, {1, 33}, {1, 11}, {1, 10}}

kglr
  • 394,356
  • 18
  • 477
  • 896
1

Here is another solution, based on Table. For a toy list,

bill = Range[5]
Flatten[Table[{1, bill[[j]]}, {i, 1, 1}, {j, 1, 5}], 1]
MatrixForm[ted]

The last line is for formating reasons, and Flatten removes a redundant pair of brackets.

Titus
  • 1,370
  • 9
  • 18