Answers for "numpy ones"

2

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
Posted by: Guest on October-04-2020
1

numpy ones

import numpy
print(numpy.ones((2, 3), dtype=int))
# creates the array of the shape (2, 3) of value 1 in its each cell
print(numpy.ones(6, dtype=str) 
# creates an array of size 6 with values of '1'
Posted by: Guest on April-15-2021

Code answers related to "numpy ones"

Python Answers by Framework

Browse Popular Code Answers by Language