Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python how to make an array of ones

# Basic syntax:
np.ones((number_rows, number_cols), dtype=int)

# Example usage:
import numpy as np
np.ones((5, 3), dtype=int)
array([[1, 1, 1],
       [1, 1, 1],
       [1, 1, 1],
       [1, 1, 1],
       [1, 1, 1]])

# Note, use np.zeros to create an array of zeros
Source by docs.scipy.org #
 
PREVIOUS NEXT
Tagged: #python #array
ADD COMMENT
Topic
Name
6+8 =