<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def cores_orthogonalization_step(coresX, dim, left_to_right=True):
 """TT-Tensor X orthogonalization step. The function can change the shape of some cores. """

    cc = coresX[dim]
    r1, n, r2 = cc.shape
    if left_to_right:
        # Left to right orthogonalization step.
        assert(0 <= dim < len(coresX) - 1)
        cc, rr = np.linalg.qr(reshape(cc, (-1, r2)))
        r2 = cc.shape[1]
        coresX[dim] = reshape(cc, (r1, n, r2))
        coresX[dim+1] = np.tensordot(rr, coresX[dim+1], 1)
    else:
        # Right to left orthogonalization step.
        assert(0 < dim < len(coresX))
        cc, rr = np.linalg.qr(reshape(cc, (r1, -1)).T)
        r1 = cc.shape[1]
        coresX[dim] = reshape(cc.T, (r1, n, r2))
        coresX[dim-1] = np.tensordot(coresX[dim-1], rr.T, 1)
    return coresX