# How to calculate the square root of a feature attribute?

I have a polygon shapefile with over 16k features. Each has an attribute (Double, Precision(10) Scale (2)) that I am trying to calculate the square root of, and store in new field. Is there a tool, field calculator code block, or script I can leverage?

Example: Square root of 16 is (4). (not looking for root mean square).

I see there are functions in Spatial Analyst for square root calculations on rasters, but I cant seem to locate any for shapefiles.

-

Using Field Calculator, either VB Script `Sqr([FIELDNAME])` or Python `math.sqrt(!FIELDNAME!)` under the Number Type will yield square roots.

You can either calculate into a new field, or on the field itself.

-
Sorry for the delay, thanks for this solution. The issue i run into with this is the calculation runs into an error once the first record is reached that has a negative (-) value and then stops calculating the remaining records in the table/feature class. Any thoughts on how to address this? The reason for negative values is that the Square root calculation is part of a larger standard deviation outcome I am trying to accomplish. The square root calc is being applied to the variance. – marracci Sep 3 '14 at 19:24
Isn't the square of a negative number, the normal square root with 'i' added to the end? If so, change the numbers to positive, making sure to flag whether they were previously negative, and run the calculation – Maksim Sep 3 '14 at 19:31

Maksim already provided the answer with ArcGIS, so here is the (very similar) QGIS solution

right click on your shapefile to open its attribute table

click "toggle edit mode" button (a pencil) (or ctrl+E)

on the right, click the icon for field calculator (an abacus) (or ctrl + I)

write `sqrt(name_of_field)` (EDIT : or `sqrt(abs(name_of_field))` when you need an output even with negative value)

Note that you can check "create in a new field" directly from the field calculator (contrary to ArcGIS where you need to create your field first, and run the field calculator on the field where you right-click) if you want.

-
This works just fine, except for square root of negative values. QGIS enters 'nan' (I'm assuming means 'Not A Number') for those records with a negative (-) value. Any thoughts on calculating square root on both positive and negative numbers? The reason for negative values is that the Square root calculation is part of a larger standard deviation outcome I am trying to accomplish. The square root calc is being applied to the variance. – marracci Sep 3 '14 at 19:26
I gave Maksim the Accepted Answer since it came in first overall and works as a calculation. Your answer using QGIS also is correct, and works. Using Maksim's comment in the Esri answer below: "change the numbers to positive, making sure to flag whether they were previously negative, and run the calculation" - this approach will also work in QGIS. Thank You. – marracci Sep 3 '14 at 19:37
I don't know any example of negative variance if you work with real number. Maybe it is a correlation value and not a variance. – radouxju Sep 3 '14 at 19:40
In this case the variance is calculated from 30 years of precipitation data, and for a given polygon the average difference from mean is negative (more years under mean than over, but the outliers have bumped the mean higher). – marracci Sep 3 '14 at 19:43
maybe we can discuss this in the chat room, but variance is always positive. so you take the square root of the average difference, not the square root of the variance. – radouxju Sep 3 '14 at 19:53