Here's one way with masking -
def skip_one(a):
n = len(a)
return np.repeat(a[None],n,axis=0)[~np.eye(n,dtype=bool)].reshape(n,-1)
Alternative #1 :
Save on memory with the replication, use np.broadcast_to(a,(n,n)) to replace np.repeat(a[None],n,axis=0).
Alternative #2 :
Replace last step with np.tile based code to bring in more compact-ness -
np.tile(a,(n,1))[~np.eye(n,dtype=bool)].reshape(n,-1)
Alternative #3 :
Use a custom made mask. Hence, replace the second step with -
np.broadcast_to(a,(n,n))[np.not_equal.outer(*[range(n)]*2)].reshape(n,-1)
Sample run -
In [22]: a
Out[22]: array([4, 7, 3, 8])
In [23]: skip_one(a)
Out[23]:
array([[7, 3, 8],
[4, 3, 8],
[4, 7, 8],
[4, 7, 3]])