'What happens when you store a numpy array with not enough memory allocated?

I was just playing around with np.array and its memory allocation, I expected that if you tried to store an array that was too big for the memory allocation you would just get an error or would just store the first x number of digits. Instead I just got back seemingly random numbers. What is going on behind the scenes here?

import numpy as np

def create_new_array(num_list):
  new_array = np.array(num_list,np.int8)
  return print(new_array)

create_new_array([31112 , 32321, 24567,456,324,789])

output: [-120, 65, -9, -56, 68, 21]

Changing the input values slightly gives completly differnt outputs and I'm very curiouse as to why this is.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source