博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Python中的numpy.square()
阅读量:2532 次
发布时间:2019-05-11

本文共 1630 字,大约阅读时间需要 5 分钟。

Python numpy.square() function returns a new array with the element value as the square of the source array elements. The source array remains unchanged.

Python numpy.square()函数返回一个新数组,该数组的元素值为源数组元素的平方。 源阵列保持不变。

Python numpy.square()示例 (Python numpy.square() Examples)

It’s a utility function to quickly get the square of the matrix elements. Let’s look at the examples of numpy square() function with integer, float, and complex type array elements.

它是一种实用功能,可以快速获取矩阵元素的平方。 让我们看一下带有整数,浮点数和复杂类型数组元素的numpy square()函数的示例。

1. numpy square()int数组 (1. numpy square() int array)

import numpy as np# intsarray_2d = np.array([[1, 2, 3], [4, 5, 6]])print(f'Source Array:\n{array_2d}')array_2d_square = np.square(array_2d)print(f'Squared Array:\n{array_2d_square}')

Output:

输出:

Source Array:[[1 2 3] [4 5 6]]Squared Array:[[ 1  4  9] [16 25 36]]

2. numpy square()浮点数组 (2. numpy square() floating point array)

import numpy as nparray_2d_float = np.array([1.2, 2.3, 5])print(f'Source Array:\n{array_2d_float}')array_2d_float_square = np.square(array_2d_float)print(f'Squared Array:\n{array_2d_float_square}')

Output:

输出:

Source Array:[1.2 2.3 5. ]Squared Array:[ 1.44  5.29 25.  ]

Notice that the integer in the floating-point array has been converted to a .

请注意,浮点数组中的整数已转换为 。

3. numpy square()复数数组 (3. numpy square() complex numbers array)

arr = np.array([1 + 2j, 2 + 3j, 4])print(f'Source Array:\n{arr}')arr_square = np.square(arr)print(f'Squared Array:\n{arr_square}')

Output:

输出:

Source Array:[1.+2.j 2.+3.j 4.+0.j]Squared Array:[-3. +4.j -5.+12.j 16. +0.j]

Here the integer element is converted to a .

在这里,整数元素将转换为 。

Reference:

参考:

翻译自:

转载地址:http://bclzd.baihongyu.com/

你可能感兴趣的文章
ASP.NET MVC:通过 FileResult 向 浏览器 发送文件
查看>>
CVE-2010-2883Adobe Reader和Acrobat CoolType.dll栈缓冲区溢出漏洞分析
查看>>
使用正确的姿势跨域
查看>>
AccountManager教程
查看>>
Android学习笔记(十一)——从意图返回结果
查看>>
算法导论笔记(四)算法分析常用符号
查看>>
ultraedit激活
查看>>
总结(6)--- python基础知识点小结(细全)
查看>>
亿级曝光品牌视频的幕后设定
查看>>
ARPA
查看>>
JSP开发模式
查看>>
我的Android进阶之旅------>Android嵌入图像InsetDrawable的使用方法
查看>>
Detours信息泄漏漏洞
查看>>
win32使用拖放文件
查看>>
Android 动态显示和隐藏软键盘
查看>>
raid5什么意思?怎样做raid5?raid5 几块硬盘?
查看>>
【转】how can i build fast
查看>>
null?对象?异常?到底应该如何返回错误信息
查看>>
django登录验证码操作
查看>>
(简单)华为Nova青春 WAS-AL00的USB调试模式在哪里开启的流程
查看>>