NumPy Saving Data

Source: Internet
Author: User

Take 3*4 array A as an example:

1. A.tofile ("Filename.bin")

This method can only be saved as a binary file, and cannot save the row and column information of the current data, the file suffix is not necessarily bin or txt, but does not affect the save format, are binary.

This method of saving is required for data reading, and it is necessary to manually specify the Dtype of the read data, and if the specified format is inconsistent with the save time, the wrong data is read.

b = Numpy.fromfile ("Filename.bin", Dtype = * *)

The data read is a one-dimensional array that needs to be used

B.shape = 3,4 The number of dimensions is re-specified.

2.numpy.save ("Filename.npy", a)

With this method, the suffix name of the saved file must be set to. NPY, this format is best used only

Numpy.load ("filename") to read.

3.numpy.savetxt ("Filename.txt", a)

b = Numpy.loadtxt ("filename.txt")

For handling one-and two-dimensional arrays

NumPy Saving Data

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.