numpy使用fromstring创建矩阵的实例

作者:grey_csdn 时间:2022-02-23 09:29:49 

使用字符串创建矩阵是一个很实用的功能,之前自己尝试了很多次的小功能使用这个方法就能够简单实现。

创建长度为16的字符串,是为了方便能够在各种数据类型之间转换。


>>> s = "mytestfromstring"
>>> len(s)
16

这个功能其实是比较让我兴奋的一个小功能,因为这个简单的转换实现了ASCII码的转换


>>> np.fromstring(s,dtype=np.int8)
array([109, 121, 116, 101, 115, 116, 102, 114, 111, 109, 115, 116, 114,
   105, 110, 103], dtype=int8)

>>> np.fromstring(s,dtype=np.int16)
array([31085, 25972, 29811, 29286, 28015, 29811, 26994, 26478], dtype=int16)
>>> np.fromstring(s,dtype=np.int32)
array([1702132077, 1919317107, 1953721711, 1735289202], dtype=int32)
>>> np.fromstring(s,dtype=np.int64)
array([8243404206920464749, 7453010373645659503])
>>> np.fromstring(s,dtype=np.single)
array([ 7.21560833e+22,  4.56462917e+30,  7.71452462e+31,
    1.12586835e+24], dtype=float32)
>>> np.fromstring(s,dtype=np.float32)
array([ 7.21560833e+22,  4.56462917e+30,  7.71452462e+31,
    1.12586835e+24], dtype=float32)
>>> np.fromstring(s,dtype=np.float64)
array([ 1.19783602e+243,  1.69375610e+190])

float默认的数据宽度是64,我使用的是Mac,本身是64位的,倒不知是不是跟操作系统有关?


>>> np.fromstring(s,dtype=np.float)
array([ 1.19783602e+243,  1.69375610e+190])

来源:https://blog.csdn.net/grey_csdn/article/details/54918196

标签:numpy,fromstring,矩阵
0
投稿

猜你喜欢

  • 关于文件命名

    2009-09-18 16:29:00
  • Python数据库反向生成Model最优方案示例

    2023-11-02 18:37:36
  • 提高MYSQL查询效率的三个有效的尝试

    2009-02-27 16:08:00
  • python 爬取腾讯视频评论的实现步骤

    2021-06-19 03:57:58
  • Python数据分析之缺失值检测与处理详解

    2021-10-04 01:09:08
  • IE下,事件触发那点破烂事儿

    2009-04-27 12:31:00
  • ASP Recordset 分页显示数据的方法(修正版)

    2011-04-10 10:42:00
  • python使用turtle库绘制奥运五环

    2021-06-21 04:22:44
  • CSS自适应宽度圆角按钮

    2007-11-20 11:38:00
  • cv2.imread 和 cv2.imdecode 用法及区别

    2023-12-03 06:15:49
  • asp实现的查询某关键词在MSSQL数据库位置的代码

    2011-02-28 11:18:00
  • Python中字典的setdefault()方法教程

    2021-11-18 08:59:00
  • python微信好友数据分析详解

    2022-01-27 20:36:39
  • 全面了解python中的类,对象,方法,属性

    2021-10-07 10:54:50
  • Python实现邮件的批量发送的示例代码

    2023-08-09 07:47:57
  • Python装饰器用法实例总结

    2023-11-18 07:37:36
  • Python利用Beautiful Soup模块修改内容方法示例

    2023-09-03 10:29:51
  • 利用python实现汉诺塔游戏

    2021-02-19 03:03:45
  • Python面向对象之接口、抽象类与多态详解

    2021-10-24 10:26:48
  • python 打印出所有的对象/模块的属性(实例代码)

    2023-09-02 21:46:15
  • asp之家 网络编程 m.aspxhome.com