Better way to do solve no. 9
sominw opened this issue · 4 comments
sominw commented
p = np.random.randint(9, size=(3,3))
Saves the overhead of reshaping.
rougier commented
Are you referring to "9. Create a 3x3 matrix with values ranging from 0 to 8 (★☆☆)"?
I think your solution is not equivalent, is it?
sominw commented
@rougier I think it is. It does output the same result- 3 x 3 matrix (in randomized manner), where values may/may not be unique (but strictly in the specified range. Please let me know otherwise?
Z = np.arange(9).reshape(3,3)
will provide a sorted matrix.
rougier commented
Maybe I wrote the question badly. In my mind, you need to have all values from 0 to 8. I used "ranged" with reference to the arange
method, maybe this the confusing part:
>>> print (np.arange(9).reshape(3,3))
array([[0, 1, 2],
[3, 4, 5],
[6, 7, 8]])
sominw commented
Ah, I see. I thought otherwise. No issues :)