A protest on Saturday afternoon attracted fewer than a dozen people, who huddled on the side of the road under a tent to escape the blazing sun and flashed signs at passing cars. They were mostly white; the protesters at large demonstrations shortly after Mr. Sterling’s death had been nearly all black.

Louisiana has lately taken a harder line to defend its police officers, who this year will become a protected class under the state’s hate crimes law.

The killing of the officers on Sunday occurred as hundreds of police officers trained in crowd-control tactics braced for protests outside the Republican National Convention in Cleveland.

Cat Brooks, the co-founder of the Anti Police-Terror Project, cautioned against criticizing activists after the attack on Sunday in Baton Rouge.

“I think anytime that there’s a loss of life — black, white, police officer, otherwise — it’s cause for us to take a moment and be sad about that life,” she said. “And I think we have to be really careful about where these shootings of police officers steer the conversation. I think it’s absurd to insinuate that a movement that is doing nothing more than demanding that the war on black life come to an end is in any way responsible for these police officers getting shot.”

Stephen Loomis, the president of the Cleveland Police Patrolmen’s Association, has urged people not to bring their guns anywhere near Cleveland’s downtown during the convention because officers are in a “heightened state.”

In Cleveland on Sunday, Steve Thacker, 57, of Westlake, Ohio, stood in the city’s Public Square holding a semiautomatic AR-15-style assault rifle — allowed under the state’s open-carry law — as news broke that several officers had been killed in Baton Rouge. When asked about Mr. Loomis’s comments and the Baton Rouge shooting, Mr. Thacker said that despite the attack, he wanted to make a statement and show that people could continue to openly carry their weapons.

“I pose no threat to anyone. I’m an American citizen. I’ve never been in trouble for anything,” said Mr. Thacker, an information technology engineer. “This is my time to come out and put my two cents’ worth in, albeit that it is a very strong statement.”