AttributeError: 'list' object has no attribute 'numpy'
@AAnirudh07 The `layer_weights` contains list of variable tensors. The list can be iterated and each tensor can be then converted with `.numpy()` method:
```
for weightTensors in layer_weights:
      weights.append(weightTensors.numpy())      
```

Please refer the working gist [here](https://colab.research.google.com/gist/pjpratik/858d9aaadd77e33fa53eb1da4d2fee30/59620.ipynb) and let us know if it helps. Thanks!

 Woah this is awesome! Thanks a lot @pjpratik!

I have one final question - Is there any particular reason why list iteration works but list indexing doesn't? List indexing thows an `IndexError: list index out of range` error.

Thanks! @AAnirudh07  I can see your first layer returns empty list as it does not contain any weights, that's why you were getting `IndexError: list index out of range` error. 

I was able to index the second layer list with out any error.

Please refer the gist [here](https://colab.research.google.com/gist/pjpratik/b33618073ea0dbabe630cc268a68fee0/59620.ipynb) and let us know if it helps.  Feel free to close the issue if it is resolved. Thanks! Ah right my bad.

Thanks for all the help! Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/59620">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/59620">No</a>

<details><summary>Click to expand!</summary> 
 
 ### Issue Type

Bug

### Have you reproduced the bug with TF nightly?

No

### Source

source

### Tensorflow Version

tf 2.11.0

### Custom Code

No

### OS Platform and Distribution

Windows 11

### Python version

3.10.9

### Current Behaviour?


Hello!
I'm trying to write a script that gets the weights (just the weights) of each layer of a keras model. I am aware of the `get_weights()` method, but I don't want to use it since it returns specific terms such as bias with the weights, so I can't tell which is which. I used `model.get_layer(layer.name).weights` to extract the weights of a particular layer. The layer weights are returned as a TensorFlow variable. Here's an example:

```shell
[<tf.Variable 'dense_2/kernel:0' shape=(256, 10) dtype=float32, numpy=
array([[-0.08837277, -0.03666556, -0.00683133, ...,  0.09055033,
         0.13219357,  0.0625298 ],
       [-0.00596744, -0.10817644, -0.08093027, ..., -0.03245946,
        -0.1296913 ,  0.14863956],
       [-0.10632615, -0.14407103, -0.09643614, ...,  0.1368066 ,
         0.09166756,  0.12455937],
       ...,
       [ 0.1320965 , -0.14804208, -0.11622404, ...,  0.14576206,
         0.02600923,  0.10927373],
       [ 0.05249688, -0.00176807, -0.06608753, ..., -0.09677176,
         0.1066353 , -0.11133642],
       [-0.07169801, -0.05865452,  0.11303747, ...,  0.11609155,
         0.03141506,  0.00285086]], dtype=float32)>]
```

Despite having a `list` type, the above output cannot be indexed: Assuming the above output is referred to as `var`; `var[0]` throws an `IndexError: list index out of range` error. 

Whenever I try to evaluate tf.Variable with the numpy() method, the error shown in the issue title appears.

Any help would be much appreciated.
Thank you!



### Standalone code to reproduce the issue

```shell
import tensorflow as tf

def get_model():
    mnist_model = tf.keras.Sequential([
    tf.keras.layers.Flatten(input_shape=(28, 28)),
    tf.keras.layers.Dense(256, activation='relu', use_bias=False),
    tf.keras.layers.Dropout(0.45),
    tf.keras.layers.Dense(256, activation='relu', use_bias=False),
    tf.keras.layers.Dropout(0.45),
    tf.keras.layers.Dense(10, use_bias=False)])
    return mnist_model


def get_model_weights(model):
    weights = []
    for index, layer in enumerate(model.layers):
        layer_weights = model.get_layer(layer.name).weights    
        layer_weights.numpy()
        weights.append(layer_weights)
    return weights

get_model_weights(get_model())
```