Let A be a square matrix of 0's and 1's, and let X be a one dimesional
vector.
The length of X is equal to the number of 1's that A has.
I would like to produce a new matrix B by traversing the matrix A row by row
and:
1- whenever i find a 0, set B in that position to zero.
2- whenever i find a
A=[[1,1,0],
... [1,0,0],
... [0,0,1]]
X=[2,9,10,3]
import numpy
A=numpy.asarray(A)
X=numpy.asarray(X)
A
array([[1, 1, 0],
[1, 0, 0],
[0, 0, 1]])
X
array([ 2, 9, 10, 3])
non_zero=numpy.nonzero(A)
non_zero
(array([0, 0, 1, 2]), array([0, 1, 0, 2]))
A[non_zero]
array([1, 1,
With A and X being arrays:
B=numpy.zeros(A.shape, A.dtype)
B[A0] = X
Armando
Quoting gerardob gberbeg...@gmail.com:
Let A be a square matrix of 0's and 1's, and let X be a one dimesional
vector.
The length of X is equal to the number of 1's that A has.
I would like to produce a new
Let A and B be two n x n matrices.
I would like to have another n x n matrix C such that
C_ij = min {A_ij, B_ij}
Example:
A = numpy.array([[2,3],[10,12]])
B = numpy.array([[1,4],[9,13]])
Output
C = [[1,3],[9,12]]
The function min(axis) of numpy seems to be only unary.
Thanks.
--
View
import numpy
A = numpy.array([[2,3],[10,12]])
B = numpy.array([[1,4],[9,13]])
C = numpy.array([A,B])
numpy.min(C,0)
array([[ 1, 3],
[ 9, 12]])
Ian
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
17/03/10 @ 11:47 (-0700), thus spake gerardob:
Let A and B be two n x n matrices.
I would like to have another n x n matrix C such that
C_ij = min {A_ij, B_ij}
Example:
A = numpy.array([[2,3],[10,12]])
B = numpy.array([[1,4],[9,13]])
Output
C = [[1,3],[9,12]]
The function
On Wed, Mar 17, 2010 at 11:47 AM, gerardob gberbeg...@gmail.com wrote:
Let A and B be two n x n matrices.
I would like to have another n x n matrix C such that
C_ij = min {A_ij, B_ij}
Example:
A = numpy.array([[2,3],[10,12]])
B = numpy.array([[1,4],[9,13]])
Output
C = [[1,3],[9,12]]
gerardob wrote:
Let A and B be two n x n matrices.
I would like to have another n x n matrix C such that
C_ij = min {A_ij, B_ij}
Example:
A = numpy.array([[2,3],[10,12]])
B = numpy.array([[1,4],[9,13]])
Output
C = [[1,3],[9,12]]
The function min(axis) of numpy seems to be only
gerardob wrote:
Let A and B be two n x n matrices.
I would like to have another n x n matrix C such that
C_ij = min {A_ij, B_ij}
In [30]: A = numpy.array([[2,3],[10,12]])
In [31]: B = numpy.array([[1,4],[9,13]])
In [32]: numpy.minimum(A,B)
Out[32]:
array([[ 1, 3],
[ 9, 12]])
Christopher Barker wrote:
In [32]: numpy.minimum(A,B)
wow! fifth to answer that one -- darn I'm slow!
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/ORR(206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA
I have another matrix operations which seems a little more complicated.
Let A be an n x n matrix and let S be a subset of {0,...,n-1}. Assume
S is represented by a binary vector s, with a 1 at the index i if i is
in S. (e.g. if S={0,3} then s = [1,0,0,1])
I re-post the question because the
Hello,
I want to divide an n x n (2-dimension) numpy array matrix A by a n
(1-dimension) array d as follows:
Take n = 2.
Let A= 2 3
1 10
and let d = [ 3 2 ]
Then i would like to have A/d = 2/3 3/3
1/2 10/2
This is to avoid loops to
On Fri, Mar 12, 2010 at 12:52, gerardo.berbeglia gberbeg...@gmail.com wrote:
Hello,
I want to divide an n x n (2-dimension) numpy array matrix A by a n
(1-dimension) array d as follows:
Take n = 2.
Let A= 2 3
1 10
and let d = [ 3 2 ]
Then i would like to have A/d = 2/3 3/3
13 matches
Mail list logo