{"id":85134,"date":"2020-03-27T20:57:06","date_gmt":"2020-03-27T12:57:06","guid":{"rendered":"http:\/\/4563.org\/?p=85134"},"modified":"2020-03-27T20:57:06","modified_gmt":"2020-03-27T12:57:06","slug":"python-%e4%b8%ad%e7%9a%84-numpy-%e5%ae%9a%e4%b9%89-dtype-%e4%b8%ba-short-%e4%bb%a5%e5%90%8e%e4%b8%ba%e4%bb%80%e4%b9%88%e8%b5%8b%e5%80%bc-32768-%e7%9a%84%e5%80%bc%e6%98%af-32768-%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=85134","title":{"rendered":"Python \u4e2d\u7684 numpy \u5b9a\u4e49 dtype \u4e3a short \u4ee5\u540e\u4e3a\u4ec0\u4e48\u8d4b\u503c 32768 \u7684\u503c\u662f-32768 \uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  Python \u4e2d\u7684 numpy \u5b9a\u4e49 dtype \u4e3a short \u4ee5\u540e\u4e3a\u4ec0\u4e48\u8d4b\u503c 32768 \u7684\u503c\u662f-32768 \uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : SystemLight <\/span>  <span><i><\/i> 9<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>a = np.array([1, 2, 3, 4, 5, 6, 32768]) a.dtype = np.short print(a)<\/p>\n<p>\u8f93\u51fa\uff1a [ 1 0 2 0 3 0 4 0 5 0 6 0 -32768 0]<\/p>\n<p>\u8f93\u51fa\u7684\u7ed3\u679c\u4e3a\u4ec0\u4e48\u5206\u6210\u4e86\u4e24\u4e2a\u503c\u4e86\u5462\uff1f<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>7<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"1400591\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : minami <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5443\uff0c\u8fd9\u662f\u88ab\u8f6c\u578b\u4e86\u5427\uff0c\u6ca1\u53d1\u73b0\u6570\u7ec4\u957f\u5ea6\u90fd\u4e0d\u5bf9\u4e86\u5417\uff1f\u4f60\u8981\u521d\u59cb\u5316\u65f6\u5c31\u6307\u5b9a dtype\uff0c\u4e0d\u8981\u8fd9\u6837\u5f3a\u8f6c                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1400592\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : junkun <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             short \u8865\u7801\u7684\u8868\u793a\u8303\u56f4\u5c31\u662f-32768~32767\uff0c\u6ca1\u529e\u6cd5\u8868\u793a 32768 \u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1400593\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : SystemLight <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @junkun \u662f\u7684\u662f\u7684\uff0c\u660e\u767d\u4e86<\/p>\n<p>@minami \u8fd8\u771f\u662f\uff0c\u611f\u8c22\u542f\u53d1\uff0c\u6211\u8f93\u51fa\u503c\u4ee5\u540e\u4ece np.short \u7c7b\u578b\u8f6c\u6210\u4e86 python int \u7c7b\u578b\uff0c\u6240\u4ee5\u6700\u9ad8\u4f4d\u53d8\u4e86\uff0c\u7b26\u53f7\u4f4d\u7f6e\u4e5f\u5c31\u53d8\u4e86<\/p>\n<p>python_val = -32769<\/p>\n<p>print(bin(python_val)) # \u7b26\u53f7\u4f4d+\u4e2d\u95f4\u6570\u5b57+\u5df2\u6709\u7684 16 \u4f4d\u6570\u5b57\u4f4d -0b1000000000000001 \u5b58\u6210\u8865\u7801 1&#8230;1&#8230;0111111111111111<\/p>\n<p>print(python_val)<\/p>\n<p>numpy_short_val = np.short(python_val) # numpy \u5f97\u5230\u4ee5\u540e\u628a\u53ea\u53d6 16 \u4f4d\uff0c\u53d1\u73b0\u6700\u9ad8\u4f4d\u662f 0 \u4e3a\u6b63\u6570\uff0c\u6b63\u6570\u539f\u7801=\u8865\u7801 0111111111111111<\/p>\n<p>print(bin(numpy_short_val)) # \u5f53 python \u518d\u8bfb\u53d6\u51fa\u6765\u65f6\uff1a0111111111111111 \u5c31\u662f 32767<\/p>\n<p>print(numpy_short_val)                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1400594\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : byaiu <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5176\u5b9e dtype \u662f\u53ef\u4ee5\u5f3a\u8f6c\u7684\uff0c\u5728\u6570\u636e\u5f88\u5927\u7684\u65f6\u5019\u662f\u5f88\u6709\u5fc5\u8981\u7684\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1400595\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : SystemLight <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @byaiu \u4f46\u662f\u6211\u8fd9\u6837\u8f6c\u6362\uff0c\u6570\u7ec4\u5927\u5c0f\u5374\u53d8\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1400596\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : byaiu <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @SystemLight \u8bf4\u660e\u539f\u59cb\u7684\u7c7b\u578b\u4e0d\u662f short \u800c\u662f int \u3002<br \/>\u6211\u4ee5\u524d\u662f\u6709\u5904\u7406\u5341\u591a\u4e2a G \u6570\u636e\u7684\u9700\u6c42\uff0c\u6570\u636e\u53ef\u4ee5\u76f4\u63a5\u7528 np.fromfile \u4ece\u6587\u4ef6\u91cc\u76f4\u63a5\u83b7\u53d6\uff0c\u540c\u65f6\u8981\u6307\u5b9a dtype \u3002\u7136\u540e\u6539\u53d8 dtype \u6765\u6309\u7167\u4e0d\u540c\u7684\u683c\u5f0f\u89c2\u5bdf\u540c\u4e00\u6570\u636e\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1400597\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : enrio <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u9493\uff0c\u5c31\u786c\u9493\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>Python \u4e2d\u7684 numpy \u5b9a&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/85134"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=85134"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/85134\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=85134"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=85134"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=85134"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}