0 votes
in Python by
Explain numpy.frombuffer() in Python

1 Answer

0 votes
by
numpy.asarray() in Python The numpy.asarray()function is used to convert the input to an array. Input includes lists, lists of tuples, tuples, tuples of tuples,etc,. Syntax

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

Parameter arr : This parameter includes theinput data, in any form that can be converted to an array. This includes lists, tuples, lists of tuples,tuples of tuples, tuples of listsetc,. 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 the array interpretation of arr. If the parameter ‘arr’ is a subclass, a base class is returned. Example 1

# Python Programming giving an example for

# numpy.asarray() method

importnumpy as numpy

list = [2, 4, 6, 7, 9]

print ("Input  list : ", list)

arr = numpy.asarray(list)

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

Output Input  list :

[2, 4, 6, 7, 9]

output array from input list :

[2 4 6 7 9]

Example 2

# Python Programming giving an example for

# numpy.asarray() method using tuple

importnumpy as numpy

tuple = ([1, 2, 3], [4, 5, 6])

print ("Input  tuple : ", tuple)

arr = numpy.asarray(tuple)

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

Output Input  touple :

([1, 2, 3], [4, 5, 6])

output array from input touple :

[[1 2 3]

[4 5 6]]

Related questions

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