Asarray in numpy in Python

Source: Internet
Author: User

Time: 2014.06.25

Location: Base

---------------------------------------------------------------------------------

I. Brief Introduction

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

Function Description: converts input data (list of lists, tuples, lists of tuples, and so on) to a matrix.
A: array-based input data, including list, list of tuples, lists of tuples, and ndarrays
Dtype:
The data type is derived from the input data.

---------------------------------------------------------------------------------

Ii. instance 2.1 converts the list to an array
from numpy import asarraymy_list=[1,2,3,4]asarray(my_list)
Output: array ([1, 2, 3, 4]) Note: asarray does not process or copy data that is already an array. It can be verified as follows:
from numpy import arrayarray([1,2,3,4])asarray(a) is a
Output: True
Note: When dtype is set, only dtpye data is copied when not at the same time, for example:
A = array ([1, 2, 4], dtype = numpy. float32) asarray (a, dtype = numpy. float32) is a # output Trueasarray (a, dtype = numpy. float64) is a # output False
2.2 convert the list to a matrix
Asarray ([1 ., 2], [3, 4], [5, 6]) asarray ([1 ., 2], [3, 4], [5, 6]). shape # output (3, 2) asarray ([1 ., 2], [3, 4], [5, 6]) [] # The value of column 0 in the second row is 5.

2.3 convert the list of tuples to a matrix
asarray([(1,2,3),(4,5,6),(7,8,9)])



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.