Change language

numpy.square () in Python

Parameters :

  arr:   [array_like]  Input array or object whose elements, we need to square. 

Return:

 An array with square value of each array. 

Code # 1: Work

# Python program explaining
# square () function

 

import numpy as np

  

arr1 = [ 1 , - 3 , 15 , - 466 ]

print ( "Square Value of arr1:" , np.square (arr1))

 

arr2 = [ 23 , - 56 ]

print ( "Square Value of arr2:" , np.square (arr2) )

Output:

 Square Value of arr1: [1 9 225 217156] Square Value of arr2: [529 3136] 

Code # 2: Working with Complex Numbers

# Python program explaining
# square () function

 

import numpy as np

 

a = 4 + 3j

print ( "Square (4 + 3j):" , np.square (a))

 

b = 16 + 13j

print ( " Square value (16 + 13j): " , np.square (b))

Output:

 Square (4 + 3j): (7 + 24j) Square value (16 + 13j): (87 + 416j) 

Code # 3: Graphical representation of numpy.square ()  

# Python program explaining
# square () function

 

import numpy as np

import matplotlib.pyplot as plt

 

a = np.linspace (start = - 5 , stop = 5 ,

num = 6 , endpoint = True )

 

print ( " Graphical Representation: " , np.square (a))

  

plt.title ( "blue: with square red: without square" )

plt.plot (a, np.square (a))

 

plt.plot (a, a, color = ’red’ )

plt.show ()

Output:

 Graphical Representation: [25. 9. 1. 1. 1. 9. 25.] 

Links:
https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.absolute .html
,

Shop

Gifts for programmers

Learn programming in R: courses

$FREE
Gifts for programmers

Best Python online courses for 2022

$FREE
Gifts for programmers

Best laptop for Fortnite

$399+
Gifts for programmers

Best laptop for Excel

$
Gifts for programmers

Best laptop for Solidworks

$399+
Gifts for programmers

Best laptop for Roblox

$399+
Gifts for programmers

Best computer for crypto mining

$499+
Gifts for programmers

Best laptop for Sims 4

$

Latest questions

PythonStackOverflow

Common xlabel/ylabel for matplotlib subplots

1947 answers

PythonStackOverflow

Check if one list is a subset of another in Python

1173 answers

PythonStackOverflow

How to specify multiple return types using type-hints

1002 answers

PythonStackOverflow

Printing words vertically in Python

909 answers

PythonStackOverflow

Python Extract words from a given string

798 answers

PythonStackOverflow

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

606 answers

PythonStackOverflow

Python os.path.join () method

384 answers

PythonStackOverflow

Flake8: Ignore specific warning for entire file

360 answers

News


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

How to specify multiple return types using type-hints

Printing words vertically in Python

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically