[Numpy-discussion] complex diagonal matrix

Joachim Saul list at jsaul.de
Sun Jan 26 04:03:05 EST 2003


* baecker at physik.tu-dresden.de [26.01.2003 11:40]:
> I just wondered if there is a "nicer" way of generating
> a complex diagonal matrix than
>   a)
>      v=arange(10,typecode=Complex)
>      mat=diag(v)
>   b)
>      v=arange(10)
>      mat=diag(v)+0j
>
> Namely, wouldn't something like
>   v=arange(10)
>   mat=diag(v,typecode=Complex)
> be nicer?

No, because diag() is supposed to create a diagonal, but *not* to
cast to another type. If you wanted to add that "functionality" to
functions like diag(), you would also have to add it to functions
like reshape() etc., i.e. practically everywhere.

The way it is handled now is reasonably simple and flexible, and
there is really no advantage of your suggestion compared to
approach a).

Cheers,
Joachim




More information about the NumPy-Discussion mailing list