import torch


def stack_as_batch(tensor: torch.Tensor, n_repeats=1, dim=0) -> torch.Tensor:
	"""Inserts new dim dimension, and stacks tensor n times along that dimension"""
	res = tensor.unsqueeze(dim)
	repeats = [1] * res.ndim
	repeats[dim] = n_repeats # repeat across target dimension
	res = res.repeat(*repeats)
	return res