Thursday, September 4, 2025
HomeLanguagesPython | sympy.ones() method

Python | sympy.ones() method

With the help of sympy.ones() method, we can create a matrix having dimension nxm and filled with ones by using sympy.ones() method.

Syntax : sympy.ones()
Return : Return a ones matrix.

Example #1 :
In this example, we can see that by using sympy.ones() method, we are able to create the ones matrix having dimension nxn all filled with ones, where nxm will be pass as a parameter.




# import sympy
from sympy import *
  
# Use sympy.ones() method
mat = ones(3, 4)
   
print(mat)


Output :

Matrix([
[1, 1, 1, 1],
[1, 1, 1, 1],
[1, 1, 1, 1]])

Example #2 :




# import sympy
from sympy import *
  
# Use sympy.ones() method
mat = ones(3, 2)
   
print(mat)


Output :

Matrix([
[1, 1],
[1, 1],
[1, 1]])

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32261 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6626 POSTS0 COMMENTS
Nicole Veronica
11795 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11855 POSTS0 COMMENTS
Shaida Kate Naidoo
6747 POSTS0 COMMENTS
Ted Musemwa
7023 POSTS0 COMMENTS
Thapelo Manthata
6695 POSTS0 COMMENTS
Umr Jansen
6714 POSTS0 COMMENTS