Ask Your Question

Vector.normalize() function

asked 2011-08-27 19:29:23 -0600

rhoslug gravatar image

My question is something of a small complaint and need of an explination. Why is the normalize() function for vectors defined as it is, and not the "normal" way one would expect? This is somewhat confusing and frustrating especially if you need to have a normalized vector and what you get is a vector divided by the first non-zero element.

edit retag flag offensive close merge delete


This sounds like a good question. Can you post an explicit example in an edit to your question, just to make it easy to verify for others looking at it?

kcrisman gravatar imagekcrisman ( 2011-08-29 02:59:12 -0600 )edit

2 answers

Sort by » oldest newest most voted

answered 2013-06-03 12:31:13 -0600

Eviatar Bach gravatar image

updated 2013-06-03 12:33:59 -0600

Note that as of Sage 5.7 (see trac #13393) the normalized method does what you'd expect, normalize has been deprecated, and monic is the old functionality.

sage: v = vector([3, 2, 1])
sage: v.normalized()
(3/14*sqrt(14), 1/7*sqrt(14), 1/14*sqrt(14))
sage: v.monic()
(1, 2/3, 1/3)
edit flag offensive delete link more

answered 2011-08-29 05:19:09 -0600

benjaminfjones gravatar image

updated 2011-08-29 05:19:32 -0600

You can easily figure out what any given function or method does by examining its docstring as follows:

sage: v = vector([3,0,9])
sage: v.normalize?

Type:       builtin_function_or_method
Base Class: <type 'builtin_function_or_method'>
String Form:    <built-in method normalize of sage.modules.vector_integer_dense.Vector_integer_dense object at 0x4badd08>
Namespace:  Interactive
Definition: v.normalize(self)

       Return this vector divided through by the first nonzero entry of
       this vector.


          sage: v = vector(QQ,[0,4/3,5,1,2])
          sage: v.normalize()
          (0, 1, 15/4, 3/4, 3/2)

So there shouldn't be any confusion about what this method does. The operation that is performed by this method is a perfectly reasonable notion of "normalization". It depends on the context, of course. This definition of normalize is probably useful when working with projective spaces or doing Guass-Jordan elimination.

To compute the unit vector in the direction of v, you could do:

sage: v/v.norm()
(1/10*sqrt(10), 0, 3/10*sqrt(10))
edit flag offensive delete link more

Your Answer


Add Answer

Question Tools


Asked: 2011-08-27 19:29:23 -0600

Seen: 8,650 times

Last updated: Jun 03 '13