The fatal police shootings of two black men in Louisiana and Minnesota show the U.S. has a "serious problem," President Barack Obama said Thursday. He said he shares feelings of "anger, frustration and grief" that police killings have triggered across the country.

In his first public reaction to the shootings, Obama said it is clear they were not isolated incidents, adding that the U.S. had "seen such tragedies far too many times." He said all Americans should be "deeply troubled" by the deaths in Baton Rouge and suburban St. Paul.

"They are symptomatic of the broader challenges within our criminal justice system, the racial disparities that appear across the system year after year, and the resulting lack of trust that exists between law enforcement and too many of the communities they serve," Obama wrote in a Facebook post.

Obama's diagnosis of the problem reflected a growing sense of frustration and willingness to speak out publicly about police killings despite the risk of making law enforcement officers feel under attack.

The White House has sought to avoid weighing in on specific cases, particularly while they're being investigated, and Obama said he was limited in what he could say about the facts. Early in his presidency, Obama caused a major stir when he said a Massachusetts officer had "acted stupidly" in arresting a black Harvard University professor at his home.

Yet despite Obama's efforts to bridge misunderstandings between African-Americans and the police, the problem clearly persists, and the wide use of cellphone cameras and social media has thrust the issue further into public view. In 2014, Obama created a task force to develop modern policing guidelines, and he urged local communities and policing agencies to implement those recommendations drafted by the Justice Department.

"To admit we've got a serious problem in no way contradicts our respect and appreciation for the vast majority of police officers who put their lives on the line to protect us every single day," Obama said. "It is to say that, as a nation, we can and must do better to institute the best practices that reduce the appearance or reality of racial bias in law enforcement."

Obama said he is "encouraged" that the Justice Department is conducting a civil rights investigation into the incident in Louisiana, where 37-year-old Alton Sterling was fatally shot Tuesday as he tussled with two white officers outside a convenience store in a predominantly black neighborhood. The shooting was caught on tape and went viral online.

On Wednesday in Minnesota, a man identified as 32-year-old Philando Castile was shot to death during a traffic stop. His girlfriend posted video of the aftermath of his killing live on Facebook, saying he had been shot "for no apparent reason" while reaching for his wallet as an officer had asked.

Obama has wrestled for much of his presidency with the policing issue, the "Black Lives Matter" movement and his role as the first black president in responding to it. After the issue burst into the spotlight in 2012 with the shooting of 17-year-old Trayvon Martin in Florida, Obama insisted the U.S. take the issue seriously and added, "If I had a son, he'd look like Trayvon."