Goal
I have a NumPy array
true_direction = np.array([1,2,3]).reshape(1,3)
which I want to insert into a Polars DataFrame; that is, repeat this array in every row of the DataFrame.
What I have tried
Below are what I have tried currently
- Repeat the numpy array and use
.with_column():
The problem would be I have to somehow get the shape of the DataFrame beforehand, which is kind of annoying..with_columns( pl.Series( np.repeat(true_direction, repeats=912, axis=0) ).alias('true_direction') ) - Another way is to not start out with a numpy array
in which case I can usetrue_direction = [1,2,3]pl.lit()(suggested by ChatGpt)
The problem here is then I'd have to manually convert the.with_columns( pl.lit(true_direction) # .cast(pl.Array(pl.Float64, 3)) .alias('true_direction') )list[f64]column into anarray[f64,3]column since I need to take a dot product later on.
My question
Is there a more Polaric way to do this?