У меня есть df типа:
# /// script
# requires-python = ">=3.13"
# dependencies = [
# "polars",
# ]
# ///
import polars as pl
df = pl.DataFrame(
{
"points": [
[
[1.0, 2.0],
],
[
[3.0, 4.0],
[5.0, 6.0],
],
[
[7.0, 8.0],
[9.0, 10.0],
[11.0, 12.0],
],
],
},
schema={
"points": pl.List(pl.Array(pl.Float32, 2)),
},
)
"""
shape: (3, 1)
┌─────────────────────────────────┐
│ points │
│ --- │
│ list[array[f32, 2]] │
╞═════════════════════════════════╡
│ [[1.0, 2.0]] │
│ [[3.0, 4.0], [5.0, 6.0]] │
│ [[7.0, 8.0], [9.0, 10.0], [11.… │
└─────────────────────────────────┘
"""
Каждая точка представляет пару (x, y). Как разделить все x на 2 и все y на 4.
shape: (3, 1)
┌─────────────────────────────────┐
│ points │
│ --- │
│ list[array[f32, 2]] │
╞═════════════════════════════════╡
│ [[0.5, 0.5]] │
│ [[1.5, 1.0], [2.5, 1.5]] │
│ [[3.5, 2.0], [4.5, 2.5], [5.5,… │
└─────────────────────────────────┘
Подробнее здесь: https://stackoverflow.com/questions/795 ... s-in-place