前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【数据分析与可视化】Python的input和output

【数据分析与可视化】Python的input和output

作者头像
瑞新
发布2020-07-07 20:15:40
8260
发布2020-07-07 20:15:40
举报

有点像序列化一个对象

使用pickle序列化numpy array

import pickle
import numpy as np
# 创建一维数组
x = np.arange(10)
x
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
# 把x序列化到硬盘上 wb写2进制
f = open('x.pkl','wb')
# 把x的数据给f文件
pickle.dump(x,f)
# 查看目录文件
!ls
2to3                                 lzfgrep
2to3-3.7                             lzgrep
Assistant.app                        lzless
Designer.app                         lzma
Linguist.app                         lzmadec
Pandas数据载入与预处理.ipynb         lzmainfo
Python的input和output.ipynb          lzmore
activate                             macchangeqt
anaconda                             macdeployqt
anaconda-navigator                   makeconv
anaconda-project                     moc
asadmin                              msgattrib
autopoint                            msgcat
binstar                              msgcmp
bokeh                                msgcomm
bsdcat                               msgconv
bsdcpio                              msgen
bsdtar                               msgexec
bundle_image                         msgfilter
bunzip2                              msgfmt
bzcat                                msggrep
bzcmp                                msginit
bzdiff                               msgmerge
bzegrep                              msgunfmt
bzfgrep                              msguniq
bzgrep                               mturk
bzip2                                navigator-updater
bzip2recover                         ncursesw6-config
bzless                               ngettext

c_rehash                             numba
canbusutil                           odbc_config
captoinfo                            odbcinst
cfadmin                              openssl
chardetect                           pal2rgb
cjpeg                                pandoc
clear                                pandoc-citeproc
compile_et                           pasteurize
conda                                pcre-config
conda-build                          pcregrep
conda-convert                        pcretest
conda-debug                          pep8
conda-develop                        pip
conda-env                            pixeltool.app
conda-index                          pkgdata
conda-inspect                        pkginfo
conda-metapackage                    png-fix-itxt
conda-render                         pngfix
conda-server                         ppm2tiff
conda-skeleton                       pt2to3
conda-verify                         ptdump
cph                                  ptrepack
cq                                   pttree
curl                                 py.test
curl-config                          pyami_sendmail
curve_keygen                         pybabel
cwutil                               pycc
cygdb                                pycodestyle

cythonize                            pydoc3
dask-remote                          pydoc3.7
dask-scheduler                       pyflakes
dask-ssh                             pygmentize
dask-submit                          pyjson5
dask-worker                          pylint
dbus-cleanup-sockets                 pylupdate5
dbus-daemon                          pyrcc5
dbus-launch                          pyreverse
dbus-monitor                         pytest
dbus-run-session                     python
dbus-send                            python.app
dbus-test-tool                       python3
dbus-update-activation-environment   python3-config
dbus-uuidgen                         python3.7
deactivate                           python3.7-config
derb                                 python3.7m
djpeg                                python3.7m-config
dltest                               pythonw
dynamodb_dump                        pyuic5
dynamodb_load                        pyvenv
easy_install                         pyvenv-3.7
elbadmin                             qcollectiongenerator
envsubst                             qdbus
epylint                              qdbuscpp2xml
f2py                                 qdbusviewer.app
f2py3                                qdbusxml2cpp
f2py3.7                              qdoc
fax2ps                               qgltf
fax2tiff                             qhelpconverter
fetch_file                           qhelpgenerator
fits2bitmap                          qlalr
fitscheck                            qmake
fitsdiff                             qml.app
fitsheader                           qmlcachegen
fitsinfo                             qmleasing
fixqt4headers.pl                     qmlimportscanner
flask                                qmllint
freetype-config                      qmlmin
futurize                             qmlplugindump
gdbus                                qmlprofiler
gdbus-codegen                        qmlscene
genbrk                               qmltestrunner
gencfu                               qscxmlc
gencnval                             qt.conf
gendict                              qtattributionsscanner
genrb                                qtdiag
gettext                              qtpaths
gettext.sh                           qtplugininfo
gettextize                           qwebengine_convert_dict
gif2h5                               raw2tiff
gio                                  rcc
gio-querymodules                     rdjpgcom
glacier                              recode-sr-latin
glib-compile-resources               repc
glib-compile-schemas                 reset
glib-genmarshal                      rg
glib-gettextize                      route53
glib-mkenums                         rst2html.py
gobject-query                        rst2html4.py
gresource                            rst2html5.py
gsettings                            rst2latex.py
gss-client                           rst2man.py
gtester                              rst2odt.py
gtester-report                       rst2odt_prepstyles.py
h52gif                               rst2pseudoxml.py
h5c++                                rst2s5.py
h5cc                                 rst2xetex.py
h5clear                              rst2xml.py
h5copy                               rstpep2html.py
h5debug                              runxlrd.py
h5diff                               s3put
h5dump                               samp_hub
h5fc                                 sclient
h5format_convert                     sdbadmin
h5import                             showtable
h5jam                                sim_client
h5ls                                 sip
h5mkgrp                              skivi
h5perf_serial                        slencheck
h5redeploy                           sphinx-apidoc
h5repack                             sphinx-autogen
h5repart                             sphinx-build
h5stat                               sphinx-quickstart
h5unjam                              spyder
h5watch                              spyder3
iconv                                sqlite3
icu-config                           sqlite3_analyzer
icuinfo                              symilar
idle3                                syncqt.pl
idle3.7                              tabs
imageio_download_bin                 taskadmin
imageio_remove_bin                   tclsh
infocmp                              tclsh8.6
infotocap                            tic
instance_events                      tiff2bw
iptest                               tiff2pdf
iptest3                              tiff2ps
ipython                              tiff2rgba
ipython3                             tiffcmp
isort                                tiffcp
isql                                 tiffcrop
isympy                               tiffdither
iusql                                tiffdump
jlpm                                 tiffinfo
jpegtran                             tiffmedian
jsonschema                           tiffset
jupyter                              tiffsplit
jupyter-bundlerextension             toe
jupyter-console                      tput
jupyter-kernel                       tqdm
jupyter-kernelspec                   tset
jupyter-lab                          uic
jupyter-labextension                 unlz4
jupyter-labhub                       unlzma
jupyter-migrate                      unxz
jupyter-nbconvert                    unzstd
jupyter-nbextension                  uuclient
jupyter-notebook                     vba_extract.py
jupyter-qtconsole                    volint
jupyter-run                          wcslint
jupyter-serverextension              wheel
jupyter-troubleshoot                 wish
jupyter-trust                        wish8.6
jupyter_mac.command                  wrjpgcom
k5srvutil                            x.pkl
kadmin                               xc-avoidance
kdestroy                             xgettext
keyring                              xlwings
kill_instance                        xml2-config
kinit                                xml2-config.bak
klist                                xmlcatalog
kpasswd                              xmllint
krb5-config                          xmlpatterns
ksu                                  xmlpatternsvalidator
kswitch                              xmlwf
ktutil                               xslt-config
kvno                                 xsltproc
launch_instance                      xz
lconvert                             xzcat
libpng-config                        xzcmp
libpng16-config                      xzdec
list_instances                       xzdiff
lrelease                             xzegrep
lss3                                 xzfgrep
lupdate                              xzgrep
lz4                                  xzless
lz4c                                 xzmore
lz4cat                               zstd
lzcat                                zstdcat
lzcmp                                zstdmt
lzdiff                               创建数组.ipynb
lzegrep                              数组与矩阵运算.ipynb
# 打开文件 rb读二进制
f = open('x.pkl','rb') 
pickle.load(f)
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])

Numpy提供的序列化存储

# Numpy提供的序列化存储
np.save('Numpy序列化',x)
!ls
2to3                                 lzfgrep
2to3-3.7                             lzgrep
Assistant.app                        lzless
Designer.app                         lzma
Linguist.app                         lzmadec
Numpy序列化.npy                      lzmainfo
Pandas数据载入与预处理.ipynb         lzmore
Python的input和output.ipynb          macchangeqt
activate                             macdeployqt
anaconda                             makeconv
anaconda-navigator                   moc
anaconda-project                     msgattrib
asadmin                              msgcat
autopoint                            msgcmp
binstar                              msgcomm
bokeh                                msgconv
bsdcat                               msgen
bsdcpio                              msgexec
bsdtar                               msgfilter
bundle_image                         msgfmt
bunzip2                              msggrep
bzcat                                msginit
bzcmp                                msgmerge
bzdiff                               msgunfmt
bzegrep                              msguniq
bzfgrep                              mturk
bzgrep                               navigator-updater
bzip2                                ncursesw6-config
bzip2recover                         ngettext
bzless                               nosetests
bzmore                               numba
c_rehash                             odbc_config
canbusutil                           odbcinst
captoinfo                            openssl
cfadmin                              pal2rgb
chardetect                           pandoc
cjpeg                                pandoc-citeproc
clear                                pasteurize
compile_et                           pcre-config
conda                                pcregrep
conda-build                          pcretest
conda-convert                        pep8
conda-debug                          pip
conda-develop                        pixeltool.app
conda-env                            pkgdata
conda-index                          pkginfo
conda-inspect                        png-fix-itxt
conda-metapackage                    pngfix
conda-render                         ppm2tiff
conda-server                         pt2to3
conda-skeleton                       ptdump
conda-verify                         ptrepack
cph                                  pttree
cq                                   py.test
curl                                 pyami_sendmail
curl-config                          pybabel
curve_keygen                         pycc
cwutil                               pycodestyle
cygdb                                pydoc
cython                               pydoc3
cythonize                            pydoc3.7
dask-remote                          pyflakes
dask-scheduler                       pygmentize
dask-ssh                             pyjson5
dask-submit                          pylint
dask-worker                          pylupdate5
dbus-cleanup-sockets                 pyrcc5
dbus-daemon                          pyreverse
dbus-launch                          pytest
dbus-monitor                         python
dbus-run-session                     python.app
dbus-send                            python3
dbus-test-tool                       python3-config
dbus-update-activation-environment   python3.7
dbus-uuidgen                         python3.7-config
deactivate                           python3.7m
derb                                 python3.7m-config
djpeg                                pythonw
dltest                               pyuic5
dynamodb_dump                        pyvenv
dynamodb_load                        pyvenv-3.7
easy_install                         qcollectiongenerator
elbadmin                             qdbus
envsubst                             qdbuscpp2xml
epylint                              qdbusviewer.app
f2py                                 qdbusxml2cpp
f2py3                                qdoc
f2py3.7                              qgltf
fax2ps                               qhelpconverter
fax2tiff                             qhelpgenerator
fetch_file                           qlalr
fits2bitmap                          qmake
fitscheck                            qml.app
fitsdiff                             qmlcachegen
fitsheader                           qmleasing
fitsinfo                             qmlimportscanner
fixqt4headers.pl                     qmllint
flask                                qmlmin
freetype-config                      qmlplugindump
futurize                             qmlprofiler
gdbus                                qmlscene
gdbus-codegen                        qmltestrunner
genbrk                               qscxmlc
gencfu                               qt.conf
gencnval                             qtattributionsscanner
gendict                              qtdiag
genrb                                qtpaths
gettext                              qtplugininfo
gettext.sh                           qwebengine_convert_dict
gettextize                           raw2tiff
gif2h5                               rcc
gio                                  rdjpgcom
gio-querymodules                     recode-sr-latin
glacier                              repc
glib-compile-resources               reset
glib-compile-schemas                 rg
glib-genmarshal                      route53
glib-gettextize                      rst2html.py
glib-mkenums                         rst2html4.py
gobject-query                        rst2html5.py
gresource                            rst2latex.py
gsettings                            rst2man.py
gss-client                           rst2odt.py
gtester                              rst2odt_prepstyles.py
gtester-report                       rst2pseudoxml.py
h52gif                               rst2s5.py
h5c++                                rst2xetex.py
h5cc                                 rst2xml.py
h5clear                              rstpep2html.py
h5copy                               runxlrd.py
h5debug                              s3put
h5diff                               samp_hub
h5dump                               sclient
h5fc                                 sdbadmin
h5format_convert                     showtable
h5import                             sim_client
h5jam                                sip
h5ls                                 skivi
h5mkgrp                              slencheck
h5perf_serial                        sphinx-apidoc
h5redeploy                           sphinx-autogen
h5repack                             sphinx-build
h5repart                             sphinx-quickstart
h5stat                               spyder
h5unjam                              spyder3
h5watch                              sqlite3
iconv                                sqlite3_analyzer
icu-config                           symilar
icuinfo                              syncqt.pl
idle3                                tabs
idle3.7                              taskadmin
imageio_download_bin                 tclsh
imageio_remove_bin                   tclsh8.6
infocmp                              tic
infotocap                            tiff2bw
instance_events                      tiff2pdf
iptest                               tiff2ps
iptest3                              tiff2rgba
ipython                              tiffcmp
ipython3                             tiffcp
isort                                tiffcrop
isql                                 tiffdither
isympy                               tiffdump
iusql                                tiffinfo
jlpm                                 tiffmedian
jpegtran                             tiffset
jsonschema                           tiffsplit
jupyter                              toe
jupyter-bundlerextension             tput
jupyter-console                      tqdm
jupyter-kernel                       tset
jupyter-kernelspec                   uic
jupyter-lab                          unlz4
jupyter-labextension                 unlzma
jupyter-labhub                       unxz
jupyter-migrate                      unzstd
jupyter-nbconvert                    uuclient
jupyter-nbextension                  vba_extract.py
jupyter-notebook                     volint
jupyter-qtconsole                    wcslint
jupyter-run                          wheel
jupyter-serverextension              wish
jupyter-troubleshoot                 wish8.6
jupyter-trust                        wrjpgcom
jupyter_mac.command                  x.pkl
k5srvutil                            xc-avoidance
kadmin                               xgettext
kdestroy                             xlwings
keyring                              xml2-config
kill_instance                        xml2-config.bak
kinit                                xmlcatalog
klist                                xmllint
kpasswd                              xmlpatterns
krb5-config                          xmlpatternsvalidator
ksu                                  xmlwf
kswitch                              xslt-config
ktutil                               xsltproc
kvno                                 xz
launch_instance                      xzcat
lconvert                             xzcmp
libpng-config                        xzdec
libpng16-config                      xzdiff
list_instances                       xzegrep
lrelease                             xzfgrep
lss3                                 xzgrep
lupdate                              xzless
lz4                                  xzmore
lz4c                                 zstd
lz4cat                               zstdcat
lzcat                                zstdmt
lzcmp                                创建数组.ipynb
lzdiff                               数组与矩阵运算.ipynb
lzegrep
np.load('Numpy序列化.npy')
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
# 序列化多个(多条数据同时压缩到一个文件内)
y = np.arange(20)
y
array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,
       17, 18, 19])
np.savez('Numpy多序列化',a = x, b = y)
!ls
2to3                                 lzegrep
2to3-3.7                             lzfgrep
Assistant.app                        lzgrep
Designer.app                         lzless
Linguist.app                         lzma
Numpy序列化.npy                      lzmadec
Numpy多序列化.npz                    lzmainfo
Pandas数据载入与预处理.ipynb         lzmore
Python的input和output.ipynb          macchangeqt
activate                             macdeployqt
anaconda                             makeconv
anaconda-navigator                   moc
anaconda-project                     msgattrib
asadmin                              msgcat
autopoint                            msgcmp
binstar                              msgcomm
bokeh                                msgconv
bsdcat                               msgen
bsdcpio                              msgexec
bsdtar                               msgfilter
bundle_image                         msgfmt
bunzip2                              msggrep
bzcat                                msginit
bzcmp                                msgmerge
bzdiff                               msgunfmt
bzegrep                              msguniq
bzfgrep                              mturk
bzgrep                               navigator-updater
bzip2                                ncursesw6-config
bzip2recover                         ngettext
bzless                               nosetests
bzmore                               numba
c_rehash                             odbc_config
canbusutil                           odbcinst
captoinfo                            openssl
cfadmin                              pal2rgb
chardetect                           pandoc
cjpeg                                pandoc-citeproc
clear                                pasteurize
compile_et                           pcre-config
conda                                pcregrep
conda-build                          pcretest
conda-convert                        pep8
conda-debug                          pip
conda-develop                        pixeltool.app
conda-env                            pkgdata
conda-index                          pkginfo
conda-inspect                        png-fix-itxt
conda-metapackage                    pngfix
conda-render                         ppm2tiff
conda-server                         pt2to3
conda-skeleton                       ptdump
conda-verify                         ptrepack
cph                                  pttree
cq                                   py.test
curl                                 pyami_sendmail
curl-config                          pybabel
curve_keygen                         pycc
cwutil                               pycodestyle
cygdb                                pydoc
cython                               pydoc3
cythonize                            pydoc3.7
dask-remote                          pyflakes
dask-scheduler                       pygmentize
dask-ssh                             pyjson5
dask-submit                          pylint
dask-worker                          pylupdate5
dbus-cleanup-sockets                 pyrcc5
dbus-daemon                          pyreverse
dbus-launch                          pytest
dbus-monitor                         python
dbus-run-session                     python.app
dbus-send                            python3
dbus-test-tool                       python3-config
dbus-update-activation-environment   python3.7
dbus-uuidgen                         python3.7-config
deactivate                           python3.7m
derb                                 python3.7m-config
djpeg                                pythonw
dltest                               pyuic5
dynamodb_dump                        pyvenv
dynamodb_load                        pyvenv-3.7
easy_install                         qcollectiongenerator
elbadmin                             qdbus
envsubst                             qdbuscpp2xml
epylint                              qdbusviewer.app
f2py                                 qdbusxml2cpp
f2py3                                qdoc
f2py3.7                              qgltf
fax2ps                               qhelpconverter
fax2tiff                             qhelpgenerator
fetch_file                           qlalr
fits2bitmap                          qmake
fitscheck                            qml.app
fitsdiff                             qmlcachegen
fitsheader                           qmleasing
fitsinfo                             qmlimportscanner
fixqt4headers.pl                     qmllint
flask                                qmlmin
freetype-config                      qmlplugindump
futurize                             qmlprofiler
gdbus                                qmlscene
gdbus-codegen                        qmltestrunner
genbrk                               qscxmlc
gencfu                               qt.conf
gencnval                             qtattributionsscanner
gendict                              qtdiag
genrb                                qtpaths
gettext                              qtplugininfo
gettext.sh                           qwebengine_convert_dict
gettextize                           raw2tiff
gif2h5                               rcc
gio                                  rdjpgcom
gio-querymodules                     recode-sr-latin
glacier                              repc
glib-compile-resources               reset
glib-compile-schemas                 rg
glib-genmarshal                      route53
glib-gettextize                      rst2html.py
glib-mkenums                         rst2html4.py
gobject-query                        rst2html5.py
gresource                            rst2latex.py
gsettings                            rst2man.py
gss-client                           rst2odt.py
gtester                              rst2odt_prepstyles.py
gtester-report                       rst2pseudoxml.py
h52gif                               rst2s5.py
h5c++                                rst2xetex.py
h5cc                                 rst2xml.py
h5clear                              rstpep2html.py
h5copy                               runxlrd.py
h5debug                              s3put
h5diff                               samp_hub
h5dump                               sclient
h5fc                                 sdbadmin
h5format_convert                     showtable
h5import                             sim_client
h5jam                                sip
h5ls                                 skivi
h5mkgrp                              slencheck
h5perf_serial                        sphinx-apidoc
h5redeploy                           sphinx-autogen
h5repack                             sphinx-build
h5repart                             sphinx-quickstart
h5stat                               spyder
h5unjam                              spyder3
h5watch                              sqlite3
iconv                                sqlite3_analyzer
icu-config                           symilar
icuinfo                              syncqt.pl
idle3                                tabs
idle3.7                              taskadmin
imageio_download_bin                 tclsh
imageio_remove_bin                   tclsh8.6
infocmp                              tic
infotocap                            tiff2bw
instance_events                      tiff2pdf
iptest                               tiff2ps
iptest3                              tiff2rgba
ipython                              tiffcmp
ipython3                             tiffcp
isort                                tiffcrop
isql                                 tiffdither
isympy                               tiffdump
iusql                                tiffinfo
jlpm                                 tiffmedian
jpegtran                             tiffset
jsonschema                           tiffsplit
jupyter                              toe
jupyter-bundlerextension             tput
jupyter-console                      tqdm
jupyter-kernel                       tset
jupyter-kernelspec                   uic
jupyter-lab                          unlz4
jupyter-labextension                 unlzma
jupyter-labhub                       unxz
jupyter-migrate                      unzstd
jupyter-nbconvert                    uuclient
jupyter-nbextension                  vba_extract.py
jupyter-notebook                     volint
jupyter-qtconsole                    wcslint
jupyter-run                          wheel
jupyter-serverextension              wish
jupyter-troubleshoot                 wish8.6
jupyter-trust                        wrjpgcom
jupyter_mac.command                  x.pkl
k5srvutil                            xc-avoidance
kadmin                               xgettext
kdestroy                             xlwings
keyring                              xml2-config
kill_instance                        xml2-config.bak
kinit                                xmlcatalog
klist                                xmllint
kpasswd                              xmlpatterns
krb5-config                          xmlpatternsvalidator
ksu                                  xmlwf
kswitch                              xslt-config
ktutil                               xsltproc
kvno                                 xz
launch_instance                      xzcat
lconvert                             xzcmp
libpng-config                        xzdec
libpng16-config                      xzdiff
list_instances                       xzegrep
lrelease                             xzfgrep
lss3                                 xzgrep
lupdate                              xzless
lz4                                  xzmore
lz4c                                 zstd
lz4cat                               zstdcat
lzcat                                zstdmt
lzcmp                                创建数组.ipynb
lzdiff                               数组与矩阵运算.ipynb
c = np.load('Numpy多序列化.npz')
c['a']
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
c['b']
array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,
       17, 18, 19])

其他Numpy阅读文档

在这里插入图片描述
在这里插入图片描述
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2020-04-16 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 使用pickle序列化numpy array
  • Numpy提供的序列化存储
  • 其他Numpy阅读文档
相关产品与服务
文件存储
文件存储(Cloud File Storage,CFS)为您提供安全可靠、可扩展的共享文件存储服务。文件存储可与腾讯云服务器、容器服务、批量计算等服务搭配使用,为多个计算节点提供容量和性能可弹性扩展的高性能共享存储。腾讯云文件存储的管理界面简单、易使用,可实现对现有应用的无缝集成;按实际用量付费,为您节约成本,简化 IT 运维工作。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档