Formation of a sheared flow Z pinch