Spaces:
Running
on
Zero
Running
on
Zero
File size: 457 Bytes
bfa59ab |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Power by Zongsheng Yue 2024-08-15 16:25:07
def append_dims(x, target_dims:int):
"""Appends dimensions to the end of a tensor until it has target_dims dimensions."""
dims_to_append = target_dims - x.ndim
if dims_to_append < 0:
raise ValueError(
f"input has {x.ndim} dims but target_dims is {target_dims}, which is less"
)
return x[(...,) + (None,) * dims_to_append]
|