Skip to content

Commit

Permalink
fix getitem
Browse files Browse the repository at this point in the history
  • Loading branch information
Tumiz committed May 23, 2024
1 parent c9e998c commit a1604f5
Show file tree
Hide file tree
Showing 6 changed files with 635 additions and 43 deletions.
6 changes: 3 additions & 3 deletions docs/Transform.html

Large diffs are not rendered by default.

639 changes: 617 additions & 22 deletions docs/Vector.html

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions docs/Vector3.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/Transform.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@
" [2, 7, 9, 1, 4, 8],\n",
" [10, 3, 8, 6, 9, 5]\n",
"], columns=[\"x\", \"y\", \"z\", \"rvx\", \"rvy\", \"rvz\"])\n",
"t = py3d.Transform.from_rotation_vector(poses[[\"rvx\",\"rvy\",\"rvz\"]])@py3d.Transform.from_translation(poses[[\"x\",\"y\",\"z\"]])\n",
"t = py3d.Transform.from_rotation_vector(poses[\"rvx\",\"rvy\",\"rvz\"])@py3d.Transform.from_translation(poses[\"x\",\"y\",\"z\"])\n",
"c @ t.lerp(numpy.linspace(0, 4, 20), [0, 1, 4])"
]
},
Expand Down
5 changes: 2 additions & 3 deletions notebooks/Vector.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@
"source": [
"import py3d\n",
"a=py3d.read_csv(\"with_cols.csv\", header=1)\n",
"a[\"t\",\"x\"]"
"a[\"t\"], a[\"t\",\"x\"], a[1,2]"
]
},
{
Expand Down Expand Up @@ -390,8 +390,7 @@
"outputs": [],
"source": [
"import py3d\n",
"\n",
"pcd=py3d.read_pcd(\"ascii.pcd\").xyz.as_point(py3d.Color(r=1,g=0.5,a=0.3))"
"py3d.read_pcd(\"ascii.pcd\").xyz.as_point(py3d.Color(r=1,g=0.5,a=0.3))"
]
},
{
Expand Down
14 changes: 6 additions & 8 deletions py3d/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,14 +295,12 @@ def __imatmul__(self, value) -> Vector:
return self @ value

def __getitem__(self, keys) -> Vector:
if hasattr(self, "columns") and type(keys[0]) is str:
if type(keys) is str:
i = self.columns.index(keys)
else:
i = [self.columns.index(key) for key in keys]
return self[..., i]
else:
return super().__getitem__(keys)
if hasattr(self, "columns"):
if isinstance(keys, str):
keys = ..., self.columns.index(keys)
elif isinstance(keys, tuple) and all(isinstance(k, str) for k in keys):
keys = ..., [self.columns.index(key) for key in keys]
return super().__getitem__(keys)

def tile(self, *n) -> Vector:
return numpy.tile(self, n + self.ndim * (1,))
Expand Down

0 comments on commit a1604f5

Please sign in to comment.