Write a NumPy program to create a 10x10 matrix, in which the elements on the borders will be equal to 1, and inside 0
- برمجة بايثون
- 2021-09-10
- mhanasmh00489829403
الأجوبة
import numpy as np
x = np.ones((10, 10))
x[1:-1, 1:-1] = 0
print(x)
Sample Output:
[[ 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.] [ 1. 0. 0. 0. 0. 0. 0. 0. 0. 1.] [ 1. 0. 0. 0. 0. 0. 0. 0. 0. 1.] [ 1. 0. 0. 0. 0. 0. 0. 0. 0. 1.] [ 1. 0. 0. 0. 0. 0. 0. 0. 0. 1.] [ 1. 0. 0. 0. 0. 0. 0. 0. 0. 1.] [ 1. 0. 0. 0. 0. 0. 0. 0. 0. 1.] [ 1. 0. 0. 0. 0. 0. 0. 0. 0. 1.] [ 1. 0. 0. 0. 0. 0. 0. 0. 0. 1.] [ 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]]
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال