0 votes
in Python by
explain numpy.asanyarray() in Python with Example

1 Answer

0 votes
by
numpy.asanyarray() in Python The asanyarray() function of Python numpy class converts the input to an ndarray, but pass ndarray subclasses through. Syntax

numpy.asanyarray(a, dtype=None, order=None)

Parameter arr : This parameter includes the input data, in any form that can be converted to an array. This includes lists, tuples, lists of tuples, tuples of tuples, tuples of lists etc. dtype: It is an optional parameter. It depicts the data type of returned array, and by default, it is a float. order : This parameter states whether to use row-major (C-style) or column-major (Fortran-style) memory representation. By defaults it takes ‘C-style’.  Return This function returns an array interpretation of the parameter ‘arr’. If ‘arr’ is same as ndarray or is a subclass of ndarray, it is returnes the same value. Example 1

# Python Programming giving an example for

# numpy.asanyarray() function

importnumpy as numpy

inp_list = [2, 4, 6, 8, 10]

print ("Input  list : ", inp_list)

arr = numpy.asanyarray(inp_list)

print ("output array from input list : ", arr)

Output

Input  list :  [2, 4, 6, 8, 10]

output array from input list :  [ 2  4  6  8 10]

Example 2

# Python Programming giving an example for

# numpy.asanyarray() function

importnumpy as numpy

tuple_list = ([4, 8, 6], [1, 2, 3])

print ("Input  tuple : ", tuple_list)

arr = numpy.asanyarray(tuple_list)

print ("output array from input tuple : ", arr)

Output

Input  tuple :  ([4, 8, 6], [1, 2, 3])

output array from input tuple :  [[4 8 6]

 [1 2 3]]

Related questions

0 votes
asked May 19, 2022 in Python by john ganales
0 votes
asked May 19, 2022 in Python by john ganales
...