(Oct-02-2018, 12:32 PM)ichabod801 Wrote: Also, I think the numpy authors were trying to emulate matrix operations. Mathematicians don't divide matrices, mainly because matrix multiplication is not commutative, leading to an ambiguous definition of the inverse operation.
Dividing and multiplying
numpy.array
is possibleOutput:In [19]: N=500
...: R=0.5
...:
...: pressure_list=np.array([16,25,40])
...: expectation_val_V=np.array([445.186, 412.284, 390.5])
...: expectation_eta=(4/3 *np.pi *R**3)/expectation_val_V
...:
...:
In [20]: expectation_eta
Out[20]: array([0.00117613, 0.00127 , 0.00134084])
Elements of numpy.array
all have the same typeOutput:In [24]: pressure_list.dtype
Out[24]: dtype('int64')
and if the dtype
of an array allows for math operation (as long as shapes of arrays are compatible) - you are free to apply math operations on arrays.Output:In [51]: np.reshape(np.arange(6), (2, 3)) * np.arange(6, 9)
Out[51]:
array([[ 0, 7, 16],
[18, 28, 40]])
list
in Python is agnostic of the type of elements - which (element(s)) may be replaced by element(s) of another type dynamically, therefor math operations between lists (excluding addition - below) are meaningless.List addition is basically interpreted as list concatenation
Output:In [22]: list.__add__?
Signature: list.__add__(self, value, /)
Call signature: list.__add__(*args, **kwargs)
Type: wrapper_descriptor
String form: <slot wrapper '__add__' of 'list' objects>
Namespace: Python builtin
Docstring: Return self+value.
PS
numeric
numpy.array
may also be multiplied or divided by a scalar digital value; power op is applicable tooOutput:In [52]: np.arange(6, 9) ** 2
Out[52]: array([36, 49, 64])
PPS
WHat is inefficient - from any point of view - is the calculation of the expression below several times; redundant brackets - together with lack of spaces - reduce readability too
(4*(1-(3*np.sqrt(2))/(np.pi)*eta))
Test everything in a Python shell (iPython, Azure Notebook, etc.)
- Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
- Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
- You posted a claim that something you did not test works? Be prepared to eat your hat.