python 实现单一数字取对数与数列取对数
作者:谨墨 时间:2023-04-02 01:38:14
python取对数可以采用两种工具包,math包可对单一数字取对数,numpy可以数列整体取对数。
1、仅对单一数字取对数
import math
math.log(2) #默认以e为底
math.log(4,2)#以2为底,4的对数
即math.log(c,b) #计算以b为底,c的对数
2、对数列整体求对数
对一个数列取对数 需要numpy包
import numpy
numpy.log([2,4,8])#以e为底,分别对2,4,8取对数
numpy.log2([2,4,8])#以2为底,分别对2,4,8取对数
即numpy.loga(b)#以a为底,对数列b中的数字分别取对数
或采用循环体:
import mtah
l = []
for i in [2,4,8]:
l.append(math.log(i,2))#对list中的每一个数求以2为底的对数
补充:python如何对数组求指数以及对数
指数:
math.exp()
只能对一个数求指数,不能对数组进行批量求指数
numpy.exp()
既能对一个数求指数,也能对数组进行批量求指数
对数:
math.log()
numpy.log()
作用同上
来源:https://blog.csdn.net/weixin_43137080/article/details/85038761
标签:python,数字,数列,对数
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
攻击者是如何将PHP Phar包伪装成图像以绕过文件类型检测的(推荐)
2023-09-05 19:29:06
![](https://img.aspxhome.com/file/2023/0/55630_0s.png)
Tornado Web Server框架编写简易Python服务器
2021-10-18 09:23:52
python连接FTP服务器的实现方法
2022-04-07 14:34:03
![](https://img.aspxhome.com/file/2023/3/120553_0s.png)
MySQL数据表使用的SQL语句整理
2024-01-20 07:13:03
![](https://img.aspxhome.com/file/2023/5/68685_0s.webp)
Tensorflow加载Vgg预训练模型操作
2023-10-13 10:56:23
![](https://img.aspxhome.com/file/2023/5/80795_0s.jpg)
python eval()函数使用详情
2021-10-17 02:09:23
![](https://img.aspxhome.com/file/2023/8/103368_0s.png)
Python入门教程(四十一)Python的NumPy数组索引
2023-07-17 01:38:55
![](https://img.aspxhome.com/file/2023/5/135265_0s.png)
在vue中动态添加class类进行显示隐藏实例
2024-05-09 15:13:28
![](https://img.aspxhome.com/file/2023/7/126547_0s.jpg)
基于python的列表list和集合set操作
2023-03-20 01:38:34
![](https://img.aspxhome.com/file/2023/6/111876_0s.jpg)
Python数据库的连接实现方法与注意事项
2024-01-14 10:51:54
Python tkinter模块弹出窗口及传值回到主窗口操作详解
2023-09-27 23:03:05
![](https://img.aspxhome.com/file/2023/3/61173_0s.jpg)
asp.net gridview 72般绝技
2024-03-08 18:34:10
![](https://img.aspxhome.com/file/2023/8/77188_0s.gif)
python爬虫 requests-html的使用
2023-05-08 02:41:16
![](https://img.aspxhome.com/file/2023/1/120591_0s.png)
python reduce 函数使用详解
2022-11-01 22:20:57
![](https://img.aspxhome.com/file/2023/4/76184_0s.png)
Vue父子传递实例讲解
2023-07-02 17:03:29
BootstrapTable与KnockoutJS相结合实现增删改查功能【二】
2024-02-23 12:58:39
![](https://img.aspxhome.com/file/2023/6/56426_0s.png)
Node.js中创建和管理外部进程详解
2024-05-02 17:36:03
![](https://img.aspxhome.com/file/2023/3/129493_0s.png)
echarts柱状堆叠图实现示例(图例和x轴都是动态的)
2024-04-29 13:21:03
![](https://img.aspxhome.com/file/2023/2/132702_0s.jpg)
python提取字典key列表的方法
2023-02-01 23:35:28
Python3的介绍、安装和命令行的认识(推荐)
2022-10-09 22:45:36
![](https://img.aspxhome.com/file/2023/9/117939_0s.png)