What is sliding window averaging for arrays and how is it implemented?

Hey, I wanted to develop a code to yield out the output for sliding window averages but I couldn’t develop the logic myself. I also tried using ChatGPT but it gave this code:

which is computationally expensive and time-taking for me, though the function in itself works fine. I wanted a NumPy approach to this code as it might lessen the code size, can anyone provide me its solution?