# How do I troubleshoot when I get a Part::partd or a Part::partw error?

Mathematica has produced the following error message:

Part::partd: Part specification ... is longer than depth of object?

What is `partd`?

I think I may have flattened or (unflattened) arrays and am not sure how to locate the exact object?

-

2
Did you click on the little `>>` at the end of the error message? – rm -rf♦ Jan 16 at 0:04
Probably means that you are trying to access an array with more dimensions than it has (e.g. myArray[[i,j]] when myArray is a single dimension). – Guillochon Jan 16 at 0:42

2
@rm-rf that has never worked on my installation, so I generally discount it. – rcollyer Jan 16 at 2:08

## 1 Answer

Two of the most common error messages that users encounter when working with parts of lists are `Part::partd` and `Part::partw` (look up `Message` for the error message syntax). Both of these are because the user is trying to access an invalid part of the expression (the "object" referred to in the error message), but there's a subtle difference between the two:

### `Part::partw`

This error occurs when you're trying to obtain a part of an expression at a position longer than the `Length` of the expression (or subexpression). For example:

````exprw = {{a, b}, {c, d, e}};
exprw[[2, 3]]
(* e *)

exprw[[1, 3]]
````

`Part::partw:` "Part 3 of `{a,b}` does not exist"

You can see that we tried to access the third element of a two element list and this results in an error. In general, if you get a `partw` error, look at the size of your index and check if it makes sense to your application. If not, you've found the source of your error. If it does, then your application/model is most likely faulty and you might want to check that instead.

### `Part::partd`

This error occurs when you're trying to index the expression at a depth deeper than the maximum depth of the expression. In general, you can index the elements of an expression at `Level` $n$ by using exactly $n$ indices and you can index any element in an expression of `Depth` $d$ with most $d-1$ indices. However, when you try to index an expression at a depth greater than its maximum depth or you try to access an element at level $n$ with more than $n$ indices (which again translates to deeper depth), you get a `partd` error. For example, consider:

````exprd = {{a, b}, {c, d, {e}}};
````

The maximum depth or `Depth[exprd]` is 4. Now try indexing with 4 indices:

````exprd[[1, 1, 1, 1]]
````

`Part::partd`: "Part specification `{{a,b},{c,d,{e}}}[[1,1,1,1]]` is longer than depth of object"

So if you get a `partd` error, check to see if you're using the right number of indices for the given expression.

-

Thanks this explains it quite well. – sebastian c. Jan 16 at 10:04
lang-mma
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 6, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 20, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "github"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "english_confidence": 0.8992009162902832, "perplexity_flag": "middle"}