Question from Jupyter Lab1;
Is there a difference between np.zeros() and np.empty()?
D. np.empty() outputs an uninitialized array, but np.zeros() outputs an initialized array of value zero.
I get the idea, particularly from a memory allocation perspective, but when I run for example something like this.
I originally considered the possibility that during a conditional, uninitialized elements are automcatically initialized as 0. However, when I tried the following;
Here is the link to the reference menu. The object returned by np.empty() is initialised to none, whilst object returned by np.zeros() is initialised to zeros.
Seems I wasn’t quite understanding how NumPy gets memory from the memory allocator. The unitialized array examples with floats as its elements from your link helped.
So, when np.empty gets memory, it interprets the bytes in that string as a float, and gets some number.
That to me would explain why np.empty() == np.empty() is False, but then why is np.empty() == np.zeros() True? Guessing it could be a coincidence, but not 100%.
Sorry all, turns out it was just a coincidence in a specific Jupyter notebook I was using. When replicated locally and on an online compiler, the .empty == .zeros indeed returned False on some occassions. So, it was a coincidence.