pythonmathcot函数_NumPy数学函数介绍和用法
本文概述
Numpy包含大量数学函数, 可用于执行各种数学运算。数学函数包括三角函数, 算术函数和用于处理复数的函数。让我们讨论一下数学函数。
三角函数
Numpy包含三角函数, 用于计算弧度中不同角度的正弦, 余弦和正切。
sin, cos和tan函数返回指定角度的三角比。考虑以下示例。
例子
import numpy as np
arr = np.array([0, 30, 60, 90, 120, 150, 180])
print("\nThe sin value of the angles", end = " ")
print(np.sin(arr * np.pi/180))
print("\nThe cosine value of the angles", end = " ")
print(np.cos(arr * np.pi/180))
print("\nThe tangent value of the angles", end = " ")
print(np.tan(arr * np.pi/180))
输出
The sin value of the angles
[0.00000000e+00 5.00000000e-01 8.66025404e-01 1.00000000e+00
8.66025404e-01 5.00000000e-01 1.22464680e-16]
The cosine value of the angles
[ 1.00000000e+00 8.66025404e-01 5.00000000e-01 6.12323400e-17
-5.00000000e-01 -8.66025404e-01 -1.00000000e+00]
The tangent value of the angles [ 0.00000000e+00 5.77350269e-01 1.73205081e+00 1.63312394e+16
-1.73205081e+00 -5.77350269e-01 -1.22464680e-16]
另一方面, arcsin(), arccos()和arctan()函数返回指定角度的三角逆。
numpy.degrees()函数可用于验证这些三角函数的结果。考虑以下示例。
例子
import numpy as np
arr = np.array([0, 30, 60, 90])
print("printing the sin values of different angles")
sinval = np.sin(arr*np.pi/180)
print(sinval)
print("printing the inverse of the sin")
cosec = np.arcsin(sinval)
print(cosec)
print("printing the values in degrees")
print(np.degrees(cosec))
print("\nprinting the cos values of different angles")
cosval = np.cos(arr*np.pi/180)
print(cosval)
print("printing the inverse of the cos")
sec = np.arccos(cosval)
print(sec)
print("\nprinting the values in degrees")
print(np.degrees(sec))
print("\nprinting the tan values of different angles")
tanval = np.tan(arr*np.pi/180)
print(tanval)
print("printing the inverse of the tan")
cot = np.arctan(tanval)
print(cot)
print("\nprinting the values in degrees")
print(np.degrees(cot))
输出
printing the sin values of different angles
[0. 0.5 0.8660254 1. ]
printing the inverse of the sin
[0. 0.52359878 1.04719755 1.57079633]
printing the values in degrees
[ 0. 30. 60. 90.]
printing the cos values of different angles
[1.00000000e+00 8.66025404e-01 5.00000000e-01 6.12323400e-17]
printing the inverse of the cos
[0. 0.52359878 1.04719755 1.57079633]
printing the values in degrees
[ 0. 30. 60. 90.]
printing the tan values of different angles
[0.00000000e+00 5.77350269e-01 1.73205081e+00 1.63312394e+16]
printing the inverse of the tan
[0. 0.52359878 1.04719755 1.57079633]
printing the values in degrees
[ 0. 30. 60. 90.]
舍入函数
numpy提供了各种功能, 可用于截断十进制浮点数的值, 将其舍入为十进制数的特定精度。让我们讨论舍入函数。
numpy.around()函数
此函数返回一个十进制值, 四舍五入到所需的小数位。该函数的语法如下。
numpy.around(num, decimals)
它接受以下参数。
SN
Parameter
Description
1
num
它是输入数字。
2
decimals
它是要舍入到的小数位数。默认值为0。如果此值为负, 则小数点将移到左侧。
考虑以下示例。
例子
import numpy as np
arr = np.array([12.202, 90.23120, 123.020, 23.202])
print("printing the original array values:", end = " ")
print(arr)
print("Array values rounded off to 2 decimal position", np.around(arr, 2))
print("Array values rounded off to -1 decimal position", np.around(arr, -1))
输出
printing the original array values: [ 12.202 90.2312 123.02 23.202 ]
Array values rounded off to 2 decimal position [ 12.2 90.23 123.02 23.2 ]
Array values rounded off to -2 decimal position [ 10. 90. 120. 20.]
numpy.floor()函数
此函数用于返回输入数据的下限值, 该下限值是不大于输入值的最大整数。考虑以下示例。
例子
import numpy as np
arr = np.array([12.202, 90.23120, 123.020, 23.202])
print(np.floor(arr))
输出
[ 12. 90. 123. 23.]
numpy.ceil()函数
此函数用于返回数组值的上限值, 该值是大于数组元素的最小整数值。考虑以下示例。
例子
import numpy as np
arr = np.array([12.202, 90.23120, 123.020, 23.202])
print(np.ceil(arr))
输出
[ 13. 91. 124. 24.]
pythonmathcot函数_NumPy数学函数介绍和用法相关推荐
- Pascal中的字符串函数和数学函数
Pascal中的字符串函数和数学函数 字符串函数 求长度length 定义:function Length(S: String): Integer; 例子: var S: String; begin ...
- matlab数学函数应用,数学函数论文,关于MATLAB软件在高等数学教学中的应用相关参考文献资料-免费论文范文...
导读:本论文可用于数学函数论文范文参考下载,数学函数相关论文写作参考研究. (云南经济管理学院,昆明 650304) (Yunnan College of Business Management,Ku ...
- python数学公式代码导入_NumPy 数学函数及代数运算的实现代码
一.实验介绍 1.1 实验内容 如果你使用 Python 语言进行科学计算,那么一定会接触到NumPy.NumPy 是支持 Python 语言的数值计算扩充库,其拥有强大的多维数组处理与矩阵运算能力. ...
- SQL函数之数学函数:ABS,PI,POWER,RAND,ROUND,SQUARE, SQRT,三角函数的用法
数学函数 ABS函数(取绝对值) --ABS(绝对值)函数 SELECT ABS(-5) AS '-5的绝对值', ABS(0) AS '0的绝对值', ABS(5) AS '5的绝对值' PI(圆周 ...
- mysql od函数_Mysql数学函数不求人
所有的数学函数在一个出错的情况下返回NULL. - 单目减.改变参数的符号. mysql> select - 2; 注意,如果这个操作符与一个BIGINT使用,返回值是一个BIGINT! ...
- C语言函数——常用数学函数
该博文为原创文章,未经博主同意不得转载,如同意转载请注明博文出处 本文章博客地址:https://cplusplus.blog.csdn.net/article/details/104344326 常 ...
- mysql 条件 函数_mysql 函数 时间函数,数学函数,字符串函数,条件判断函数
=========================================== mysql 相关函数 ============================================= ...
- mysql中的各种函数(日期函数、字符串函数、数学函数...)
mysql4 函数 日期函数 字符串函数 charset concat length replace 数学函数 abs bin conv 其他函数 查询当前用户 md5 显示当前正在使用的数据库 加密 ...
- MySQL 之 单行函数(数学函数、字符串函数、日期时间函数、流程函数 )
MySQL 之 单行函数 1.数学函数 2.字符串函数 3.日期时间函数 4.流程函数 5.其他函数
最新文章
- 开启Mac充电提示音
- linux 数据恢复 ext3grep rm -rf
- asyncio简单入门(二)
- 重庆职高统考c语言,2021年重庆市中职毕业生参加高职分类考试招生文化素质测试 考试说明...
- linux du命令重定向,df命令、du命令 、磁盘分区
- C语言Huffman Encode霍夫曼编码的算法(附完整源码)
- 《剑指offer》把二叉树打印成多行
- 网络15软工个人作业5——软件工程总结
- 提升研发效率 保障数据安全——阿里云宣布数据管理DMS企业版正式商业化
- (转)淘淘商城系列——初始SolrCloud
- 利用fidder发送request
- 软件需求文档模板及说明
- Invisible Backdoor Attack with Sample-Specific Triggers
- 程序员通过什么渠道接外包项目
- 【备忘】大数据最火爆技术spark之王家林2016最新高清视频教程
- MFC隐藏任务栏图标并显示到托盘
- Kenneth Lane Thompson
- 100+个数据分析常用指标和术语
- 在vue项目中使用html2canvas截图(固定区域截图)
- 女孩上中专学财经类号还是计算机好,女生学财经类专业好吗
热门文章
- 100多个经典常用的PHP功能插件大全实例演示和下载
- ios13测试版怎么卸载软件,苹果iOS13怎么卸载软件 iOS13删除软件教程
- ML:图像数据、字符串数据等计算相似度常用的十种方法(余弦相似性、皮尔逊、闵可夫斯基距离/曼哈顿距离/欧氏距离/切比雪夫距离、马氏距离、汉明距离、编辑距离、杰卡德相似系数、相对熵/KL散度、Helli
- 游戏分类 PRG AVG
- XZ_iOS 之各大银行URL Schemes
- 概率栅格地图中Uint8_t向int8_t转换
- c语言 多元一次方程,C++实现的求解多元一次方程示例
- 博客 Gif 动态图制作 - 插入gif动态图 GifCam
- QNX Screen---Blit
- qq邮箱邮件被拦截如何找回的方法