Output
Expressions return an Array(Float32, n_components) column with one point per input row, in the same order. The column is named after the first input column; use .alias() to rename it.
out = df.select(xyz=pl.col("embedding").umap.fit_transform(n_components=3, random_state=0))
out.schema
Schema([('xyz', Array(Float32, shape=(3,)))])
To get one column per component, use .arr.get(), .arr.to_struct() or the DataFrame helper:
out.select(
pl.col("xyz").arr.get(0).alias("x"),
pl.col("xyz").arr.get(1).alias("y"),
pl.col("xyz").arr.get(2).alias("z"),
).head(3)
shape: (3, 3)| x | y | z |
|---|
| f32 | f32 | f32 |
| -1.826774 | -0.372137 | 2.518197 |
| 2.334375 | 0.831472 | 0.814163 |
| 0.087367 | -2.165499 | 1.413459 |
df.umap.fit_transform("embedding", n_components=3, random_state=0).head(3)
shape: (3, 4)| embedding | umap_0 | umap_1 | umap_2 |
|---|
| array[f32, 8] | f32 | f32 | f32 |
| [0.12573, -0.132105, … 0.947081] | -1.826774 | -0.372137 | 2.518197 |
| [-0.703735, -1.265422, … -0.732267] | 2.334375 | 0.831472 | 0.814163 |
| [-0.544259, -0.3163, … 0.35151] | 0.087367 | -2.165499 | 1.413459 |
The helper takes output="array" to add a single Array column instead, name= to name that column, and prefix= to change the umap_ prefix of the component columns.