What is the difference between Numpy's array() and asarray() functions?

前端 未结 6 804
孤城傲影
孤城傲影 2020-11-28 00:52

What is the difference between Numpy\'s array() and asarray() functions? When should you use one rather than the other? They seem to generate identical output for all the in

6条回答
  •  甜味超标
    2020-11-28 01:04

    The definition of asarray is:

    def asarray(a, dtype=None, order=None):
        return array(a, dtype, copy=False, order=order)
    

    So it is like array, except it has fewer options, and copy=False. array has copy=True by default.

    The main difference is that array (by default) will make a copy of the object, while asarray will not unless necessary.

提交回复
热议问题