Page 1 of 1

Abziehen 1 von einem Numpy -Array gibt zwei verschiedene Antworten

Posted: 18 Feb 2025, 13:17
by Guest
Warum sind Ausgänge in beiden Fällen unterschiedlich. Ich bin neu in dieser Bibliothek
Fall 1

Code: Select all

import numpy as np

np.random.seed(2)

array = np.random.random((3,1))
print('Printing array : \n', array)
print('printing array - 1 : \n',array-1)
< /code>
Output :
Printing array :
[[0.4359949 ]
[0.02592623]
[0.54966248]]
printing array - 1 :
[[-0.5640051 ]
[-0.97407377]
[-0.45033752]]
< /code>
This is ok as 1 is subtracted from each element
[b]Case 2[/b]
print('Printing array : \n',  np.random.random ((3,1))-1)

Ausgabe:

Code: Select all

Printing array :
[[-0.56467761]
[-0.5796322 ]
[-0.66966518]]
< /code>
Whay are the two outputs different?  np.random.random ((3,1)
) sollte in beiden Fällen gleich sein (gleiche Saatgut) und subtrahieren Sie so denselben Ausgang. Was versuche ich mich durcheinander?>