Python Data Science Jobs & Interviews
20.3K subscribers
187 photos
4 videos
25 files
325 links
Your go-to hub for Python and Data Science—featuring questions, answers, quizzes, and interview tips to sharpen your skills and boost your career in the data-driven world.

Admin: @Hussein_Sheikho
Download Telegram
Interview question
What is the difference between numpy.array() and numpy.asarray() when converting a Python list to a NumPy array, and how does it affect memory usage?

Answer:
numpy.array() always creates a new copy of the input data, meaning that modifications to the original list will not affect the resulting array. This ensures data isolation but increases memory usage. In contrast, numpy.asarray() only creates a copy if the input is not already a NumPy array or compatible format—otherwise, it returns a view of the existing data. This makes asarray() more memory-efficient when working with existing arrays or array-like objects. For example, if you pass an existing NumPy array to asarray(), it returns the same object without copying, whereas array() would still create a new copy even if the input is already a NumPy array

tags: #Python #NumPy #MemoryManagement #DataConversion #ArrayOperations #InterviewQuestion

By: @DataScienceQ 🚀
4