Ajay Soman
Ajay Soman

Reputation: 1651

3 Dimensional matrix in Python

How can i represent a 1x1x3 matrix in python.In matlab i have

fill_value(1,1,:) = [0; 0; 0];

I have converted this to python as

fill_value[0:1] = matrix(((0),(0),(0))).T

But it is not giving the expected result.

Upvotes: 3

Views: 559

Answers (2)

diva
diva

Reputation: 249

you can write 1x1x3 matrix using numpy.

import numpy
fill_value = numpy.array([[[0, 0, 0]]])

when we check

resol_val = fill_value.shape

output will be (1, 1, 3)

Upvotes: 2

poke
poke

Reputation: 388113

Using standard Python objects? Like this:

>>> fill_value = [[[1, 2, 3]]]
>>> fill_value[0][0][0]
1
>>> fill_value[0][0][1]
2
>>> fill_value[0][0][2]
3

You probably want to look into numpy though, which has much better support for matrices.

Upvotes: 3

Related Questions